Skip to content
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

Discussion: How to handle $ref with additional properties #531

Open
RicoSuter opened this issue Oct 23, 2017 · 7 comments
Open

Discussion: How to handle $ref with additional properties #531

RicoSuter opened this issue Oct 23, 2017 · 7 comments

Comments

@RicoSuter
Copy link
Owner

RicoSuter commented Oct 23, 2017

NJS (in NSwag) currently generates $refs as allOf if other properties are in the object:

 properties:
      audit:
        description: Audit data with information regarding document creation and modification.
        allOf:
             - $ref: '#/definitions/StoreAudit'  

Most tools expect the schema to be

 properties:
      audit:
        description: Audit data with information regarding document creation and modification.
        $ref: '#/definitions/StoreAudit'  

but this is invalid:

Any members other than $ref in a JSON Reference object are ignored.

See https://swagger.io/docs/specification/using-ref/

Discussions:

Code in question:

https://github.com/RSuter/NJsonSchema/blob/master/src/NJsonSchema/Generation/JsonSchemaGenerator.cs#L253-L274

Solutions:

  1. Add AllowReferencesWithProperties setting to always use $refs (i.e. first condition in the code is always executed)?
    • Main problem: The generated Swagger spec will be valid in AutoRest (it must be like that) and invalid in swagger-editor...
    • Whats the best name for this setting so that people understand it?
    • I'd suggest to set the default to true because most tools expect only $refs and cannot handle oneOf/allOf refs
  2. Add support for allOf/oneOf and $ref references in all other tools :-)
@RicoSuter RicoSuter changed the title Discussion: How to handle $ref with other properties Discussion: How to handle $ref with additional properties Oct 23, 2017
@alb3ric
Copy link
Contributor

alb3ric commented Oct 23, 2017

Add ForceDirectReferences setting to always use $refs

I think the ForceDirectReferences name is quite a good name.

@RicoSuter RicoSuter mentioned this issue Oct 23, 2017
8 tasks
@RicoSuter
Copy link
Owner Author

I dont like ForceDirectReferences because it implies that $ref is always used but this is not true. This would still be generated:

"Gender": {
      "oneOf": [
        {
             "type": "null"
        },
        {
          "$ref": "#/definitions/Gender"
        }
      ]
    },

maybe AllowReferencesWithAdditionalProperties?

@alb3ric
Copy link
Contributor

alb3ric commented Oct 23, 2017

Ok, but won't we mistake AdditionalProperties with the other AdditionalProperties term?

Repository owner deleted a comment from alb3ric Oct 23, 2017
@RicoSuter
Copy link
Owner Author

true... AllowReferencesWithProperties? :-)

@alb3ric
Copy link
Contributor

alb3ric commented Oct 23, 2017

Perfect

@RicoSuter
Copy link
Owner Author

Release v9.9.5 => Releasing: https://ci.appveyor.com/project/rsuter/njsonschema

@alb3ric
Copy link
Contributor

alb3ric commented Oct 23, 2017

It works great. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants