-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stringify parsed schema #266
Comments
I like the idea, might want to add it to |
do I get it right, you want to parse it to get a string and then pass it to the component that parses it again? or am I missing something? I case I'm right, isn't it better to make react component accept |
@derberg You're right about React component, it should accepts the Some code how it will look in sever-side and front-end apps: // server-side
const spec = ...
const parsedSpec = new Parser(...).parse(spec);
const stringifiedSpec = AsyncAPIDocument.stringify(parsedSpec);
response.send(stringifiedSpec, ...)
// front-end app
const parsedSchema = new AsyncAPIDocument(responseSpec);
... render React component with `schema={parsedSchema}` prop of course this is only one of use cases :) |
yup, but we do not have a use case for now as afaik we do not want the studio to have a server anymore but be client-side. also the problem with stringify is -> what will be the output? how will those circular refs be presented in stringify spec so they are not lost? did you think about this part? |
Studio will still have server-side part for login etc parts. If you don't trust me, go to source code. Studio isn't a Playground, it has a front-end part but still also backend-end part, not for render spec but for other things. Also I added two use cases in issue description, for Studio and for HTML-Template :)
I know about this part 😄 Reference (object) for circular refs will be lost, but we will still have information that schema is circular by A = {
type: "object",
properties: {
normalProp: {
type: "string",
},
circularProp: A,
}
} then after parsing and stringification you should have this: {
type: "object",
properties: {
normalProp: {
type: "string",
},
circularProp: {
'x-parser-circular': true
}
}
'x-parser-schema-id': 'A',
'x-parser-circular-props': ['circularProp']
} We don't have this yet, but we should also have information about inferred schema like: {
type: "object",
properties: {
normalProp: {
type: "string",
},
circularProp: {
'x-parser-circular': true,
'x-parser-inferred-schema': 'A', // schema id, in this case A
}
},
'x-parser-schema-id': 'A'
'x-parser-circular-props': ['circularProp']
} @derberg What do you think? |
I clicked on the link, saw some .js files but still my opinion did not change
Yes but the HTML template use case we discussed can be solved in a better way by improvement in the react component. |
But in which way? 😄 We can make improvements by passing
I use the However, I want two things in HTML-Template:
Also for studio issue, do you know that raml content type doesn't work on web, and you need nodejs app to parse your spec? I don't know exactly what the plans are for the Studio, but looking at other ideas like marketplace for specs/extensions/bindings etc server will be needed and for displaying properly parsed spec by component we will probably use two ways: parsing in browser for simple spec and for complex spec by consuming parsed spec from server. |
Additionally, I need parsed schema for hydration in case when someone pass in spec reference to file. |
tbh I was not aware of how hydration in React works, I'm surprised that in the end there are some things running in the browser anyway. If this is the only way to make it work, instead of the web component then let's do it. Just check to Gatsby to be 100% sure there is no other way |
I will :) |
@derberg I tested Gatsby and unfornatelly it doesn't work. Gatsby includes whole component with parser and also "stringify" in fly the parsed spec (to include it to the final rendered site) so circular reference in parsed spec throws stackoverflow error. Additionally Gatsby adds an internal code only used by Gatsby so site increases the final size. Can I then contribute and write the functionality for |
🤦🏼 I understand this is the ONLY solution that can help us out to use react component inside HTML template, so yeah, go ahead. Consider what @jonaslagoni said, that might be useful to have it on each model |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
This issue has been automatically marked as stale because it has not had recent activity 😴 |
Currently if you want stringify parsed schema you must do it manually by
JSON.stringify
function. However, here we have a problem with circular schemas and we must add as third parameter custom function to handle these circular schemas.I suggest to have static
stringify
function insideAsyncAPIDocument
to handle described problem:Some use cases for this feature:
new AsyncAPIDocument({parsedSchema})
to React component,asyncapi
parameter to template. We can stringify it and save it as string and and pass schema asnew AsyncAPIDocument({parsedSchema})
to React component - example: https://github.com/asyncapi/html-template/blob/41fd1a68fcfdbe5c2a52265e270cc5afbc0eec95/template/index.js#L78I can make this logic in mentioned repos but we can add it as feature to parser.
The text was updated successfully, but these errors were encountered: