-
Notifications
You must be signed in to change notification settings - Fork 26
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
Use definitions and references within the same route #19
Comments
Interesting, so I am not sure that I understand the concern about them being global. All the The api we expose is just a shorthand/helper so you dont have to write out the rather unpleasant format. So when you "use" the component you defined it just returns the ref: https://github.com/wesleytodd/express-openapi/blob/main/index.js#L94 Am I missing something about what you are asking? If so, please help me better understand. |
I have a similar issue. I'm generating TypeScript types from JSON Schema files with https://github.com/bcherny/json-schema-to-typescript tool. I want to use those JSON Schemas to generate OpenAPI docs like this import MySchema from 'schemas/MySchema.json';
openapi.component('schemas', 'MySchema', MySchema); And in {
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"SubSchema": {
"type": "object",
"properties": {
"someValue": {
"type": "string"
}
}
}
},
"title": "MySchema",
"type": "object",
"properties": {
"someArray": {
"type": "array",
"items": { "$ref": "#/definitions/SubSchema" }
}
}
} But this does not work with express-openapi. Only way I got it working was to move SubSchema to its own json file and change import MySchema from 'schemas/MySchema.json';
import SubSchema from 'schemas/SubSchema.json';
openapi.component('schemas', 'SubSchema', SubSchema);
openapi.component('schemas', 'MySchema', MySchema); After that TypeScript types generation fails because it can't find SubSchema anymore. Would it be possible to add support for |
Hey @nruotsal, I think this is a different request. I do not see a clear way to know what to merge from a call to |
I have a route that returns an object with a few properties. Each of these properties is another object with a few props. All of these nested objects follow the same schema, it's just the values that change, so I thought a definition and reference would be the best way to represent them.
https://cswr.github.io/JsonSchema/spec/definitions_references/
However, when I tried to implement them the way described in the spec, it did not work. The only example I see of refs in this project's docs are if you use
oapi.component
. I didn't think that was a great approach for my use case as these are not really global objects I want to make available.The text was updated successfully, but these errors were encountered: