Skip to content

Conversation

@marcelltoth
Copy link
Contributor

Resolves #978

@marcelltoth marcelltoth self-assigned this Mar 29, 2021
@marcelltoth marcelltoth requested a review from a team March 29, 2021 13:31
@marcelltoth marcelltoth changed the base branch from master to v7 March 29, 2021 13:31
{isJSONSchema(schema) && <SchemaViewer className="mt-6" schema={schema} examples={examples} viewMode="write" />}
{isJSONSchema(schema) && (
<Box ml={-9}>
<JsonSchemaViewer schema={schema as JSONSchema4} viewMode="write" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we casting here? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, sometimes we use our SchemaViewer wrapper, sometimes we use JSV directly. What is the logic behind that?

Copy link
Contributor Author

@marcelltoth marcelltoth Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me answer the 2nd question first:

SchemaViewer is a wrapper that renders both the schema and the corresponding examples (if any) in a tab-panel. By the new design we don't need this behavior, we simply want to render the schema. If there are any examples those will be displayed on the side inside the Response Examples panel.

Now the cast: To be honest, I don't know. I simply copied the rendering of JsonSchemaViewer from SchemaViewer to here. That had the cast, this needs the cast as well, as JSV only advertises JSONSchema4 support. Now on why, and how to resolve this cast, we should discuss with @stoplightio/void-crew , thanks for raising that. But I think this should happen separately from this as this is the same thing we've been doing since forever.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case I would think about renaming SchemaViewer somehow. It seems it's purpose is more specific than its name suggests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about that, but didn't want to expand the scope too much. If you think that's fine, I'll do it now!

Copy link
Contributor

@mmiask mmiask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, works great! 🎉

I left a few comments, although I don't feel confident enough in understanding JSV to approve.

if (contents.length === 0 && !description) return null;

const schema = contents[chosenContent]?.schema;
const examples = getExamplesObject(contents[chosenContent]?.examples || []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens to these now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, examples are now being rendered by the Response Examples component on the right.

<div className="HttpOperation__Parameters">
<div className="flex items-center">
<div className="font-medium font-mono">{parameter.name}</div>
<div className={cn('ml-2 text-sm', PropertyTypeColors[type])}>{format ? `${type}<${format}>` : type}</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the minimalistic unicolor look 😎

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, was that supposed to be changed too? I know it matches jsv types and I like it this way. Just wondering if that's the planned thing.
Also we could make that text muted so it looks the same as in jsv.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is all grayscale, see here: https://www.figma.com/file/IkNc59AU2JN5Kc1qbd2AiB/Elements?node-id=157%3A0

So it was planned for in the design. It wasn't planned to be done in this issue (the issues don't quite cover the design changes fully, actually), but as JSV removed the colors it also removed the PropertyTypeColors export so I had to do this otherwise we crash.

re muting: good idea, thanks, I'll fix that!


return (
<VStack spacing={4} divider>
{sortBy(parameters, ['required', 'name']).map((parameter, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we remove sorting by index here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did I? I believe that was simply an unused argument so I simply removed it.

{
mediaType: 'application/json',
schema: {
type: 'object' as const,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of casting 'object' as const?

Copy link
Contributor Author

@marcelltoth marcelltoth Mar 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise the entire thingy is not a valid IHttpOperation object, because JSONSchema4 inside IHttpOperation dictates that type: 'object' | 'string" | ..... You know - unless you put the as const - string literals inside objects get widened to string, and that would give me an error when passing as a prop. You can try it if you wish.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You make a very good point though. It would be much nicer to read if I simply annotated the type of the data variable instead. Let me see if that is feasible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure it's possible! Updated 😉

@netlify
Copy link

netlify bot commented Mar 29, 2021

Deploy preview for stoplight-elements ready!

Built with commit eaaf4c5

https://deploy-preview-979--stoplight-elements.netlify.app

Copy link

@mallachari mallachari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm so glad that it finally makes it into elements. Lot of work put into it by all of us.
Looks great and seems to work as good as before.

One thing I'm wondering about is that removing the border around standalone schema might make it look better. Do you think it should remain?
image

Marcell Toth added 2 commits March 30, 2021 11:27
# Conflicts:
#	packages/elements/src/components/Docs/Model/Model.tsx
#	packages/elements/src/context/Components.tsx
@marcelltoth
Copy link
Contributor Author

One thing I'm wondering about is that removing the border around standalone schema might make it look better. Do you think it should remain?

I agree. I checked that one out and it doesn't look great. I think however, that that's something to be tackled separately. It's actually not as trivial to do than the others as the schemas can possibly have examples which we need to display. So IMO it needs product input, and unfortunately it is one of those spots that are not even covered on a high level (at least I haven't found anything on Figma, not to say in an issue)

@marcelltoth marcelltoth enabled auto-merge (squash) March 30, 2021 09:51
@marcelltoth marcelltoth merged commit 3a411c8 into v7 Mar 30, 2021
@marcelltoth marcelltoth deleted the feat/jsv branch March 30, 2021 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bring new JSV into Elements

4 participants