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

Use allOf for all schemas in inheritance #733

Merged
merged 15 commits into from Sep 21, 2018

Conversation

RicoSuter
Copy link
Owner

@RicoSuter RicoSuter commented Jul 4, 2018

Closes #732

Tasks:

  • Implement correct allOf behavior
  • Check that code generators still work correctly
  • Check dictionary inheritance schema generation

@RicoSuter
Copy link
Owner Author

RicoSuter commented Aug 9, 2018

Dictionary inheritance handling (Foo = container class)

        public class Foo
        {
            public Bar Bar { get; set; }
        }

        public class Bar : Dictionary<string, string>
        {
            public string Baz { get; set; }
        }

Schema (OpenAPI 3 style)

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Foo",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "Bar": {
      "x-nullable": true,
      "oneOf": [
        {
          "$ref": "#/definitions/Bar"
        }
      ]
    }
  },
  "definitions": {
    "Bar": {
      "allOf": [
        {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "Baz": {
              "type": "string"
            }
          }
        }
      ]
    }
  }
}

Rules:

  • First schema with no reference and object type is base schema. Correct?

@RicoSuter
Copy link
Owner Author

Question: In the sample above, how can i decide which one of the schemes in allOf is the base schema (i.e. inherited) when both are inline (no schema is referenced)? When one schema is referenced and one is inline, then the referenced one is the base schema...

Also see my dictionary test in the previous comment...

@darrelmiller Is the generated schema above correct for the given C# code? Can you answer the question in this comment (is there even an answer)?

@RicoSuter
Copy link
Owner Author

For reference, there is also oneof inheritance:
#13

@bakashinji
Copy link

As far as I can see the allOf Part looks correct. I haven't used the oneOf property as of yet, but in this case it seems unnecessary to me.

@RicoSuter RicoSuter changed the title [WIP] Schema inheritance: Define schema in allOf Schema inheritance: Define schema in allOf Sep 11, 2018
@RicoSuter RicoSuter changed the title Schema inheritance: Define schema in allOf Use allOf for all schemas in inheritance Sep 21, 2018
@RicoSuter RicoSuter merged commit 74aa14f into master Sep 21, 2018
RicoSuter added a commit that referenced this pull request Sep 21, 2018
@RicoSuter
Copy link
Owner Author

RicoSuter commented Sep 23, 2018

Had to revert, because there are still some issues: New PR: #783

@RicoSuter RicoSuter deleted the features/improved-inheritance-nswag-1136 branch December 19, 2018 15:50
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.

None yet

2 participants