-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Schema Object namespaces #1362
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
Comments
Keeping in mind that I know JSON Schema well but only sort-of know OpenAPI, so this might be obvious to everyone else, but... is there a reason not to just nest definitions sections? definitions:
core:
definitions:
Foobar:
properties:
bar:
$ref : '#/definitions/core.Bar'
Bar:
properties:
foo:
type: string |
Neither OASv2 or v3 support the
However there is no reason not to use a containing object to hold the nested structure and to reference it deeply: components:
schemas:
core:
properties:
foo:
type: string
bar:
type: string
MyFoo:
$ref: '#/components/schemas/core/foo' Unsure how swagger-codegen handles that, but that's an issue for that repo, not really here. |
@brendanclement The allowed characters for naming reusable components (including schemas) is defined here https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#componentsObject and is the same as was proposed in #634 We did briefly have some guidance around the notion of namespaces, but that was simply to suggest that if you want to namespace component names then we recommend using a dot. However, this was simply a recommendation and we did not try to formalize the concept of namespaces. Code-gen tooling is going to have to take it's own approach to determining how to convert names into names and namespaces. |
Were you able to support this use case? |
OpenAPI v3.1 uses JSON Schema draft2020-12 for its schema definitions, which fully supports using |
@karenetheridge thanks for the reply. Can you provide me an example for the same? |
This should work: components:
schemas:
foo:
$defs:
bar:
type: string
paths:
/foo/{foo_id}/bar:
get:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/foo/$defs/bar' |
I am having the same problem described in #578 -- my use case has the possibility for definition names to clash. For example, you could have multiple User definitions inside a code base. I'm investigating the possibility of implementing (optional) namespaced Schema definitions and looking for feedback on this feature proposal
Some progress was made in #634 to extend legal character set in the 3.0 draft but this was removed in commit 840de94 .
I also found this thread asking for more granularity in specifying the namespace for model definitions: swagger-api/swagger-codegen#3915 - it was suggested that the OP could modify the generator and templates to achieve this
The following definitions will resolve correctly in the swagger ui editor and validator
but the swagger-codegen tooling does not currently honor the namespace. Using JavaCodegen as an example: when the definition above is translated into code
class CoreFoobar
andclass CoreBar
are emitted due to the name sanitization inDefaultCodegen.java
The example I gave above defined two normalized shapes, but I'm not sure how to handle namespaces defined in inline definitions (a de-normalized schema). e.g. Which namespace would the child object belong to?
The text was updated successfully, but these errors were encountered: