-
-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
openapi3: process discriminator mapping values as refs (#1022)
* openapi3: make StringMap generic over value This allows us to support more use cases than just a string, allowing us to attach more metadata onto these StringMap types that we cannot encode in just a string. * openapi3: process discriminator mapping values as refs While the type of the discriminator mapping values is a string in the upstream specs, it contains a jsonschema reference to a schema object. It is surprising behaviour that these refs are not handled when calling functions such as InternalizeRefs. This patch adds the data structures to store the ref internally, and updates the Loader and InternalizeRefs to handle this case. There may be several more functions that need to be updated that I am not aware of. Since it is not a full Ref object we have to do some fudging to make it work with all the existing ref handling code.
- Loading branch information
Showing
11 changed files
with
179 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
openapi: 3.1.0 | ||
info: | ||
title: foo | ||
version: 1.0.0 | ||
paths: | ||
/: | ||
get: | ||
operationId: list | ||
responses: | ||
"200": | ||
description: list | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
oneOf: | ||
- $ref: "./ext.yml#/schemas/Foo" | ||
- $ref: "./ext.yml#/schemas/Bar" | ||
discriminator: | ||
propertyName: cat | ||
mapping: | ||
foo: "./ext.yml#/schemas/Foo" | ||
bar: "./ext.yml#/schemas/Bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "foo", | ||
"version": "1.0.0" | ||
}, | ||
"paths": { | ||
"/": { | ||
"get": { | ||
"operationId": "list", | ||
"responses": { | ||
"200": { | ||
"description": "list", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/components/schemas/ext_schemas_Foo" | ||
}, | ||
{ | ||
"$ref": "#/components/schemas/ext_schemas_Bar" | ||
} | ||
], | ||
"discriminator": { | ||
"propertyName": "cat", | ||
"mapping": { | ||
"foo": "#/components/schemas/ext_schemas_Foo", | ||
"bar": "#/components/schemas/ext_schemas_Bar" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components": { | ||
"schemas": { | ||
"ext_schemas_Foo": { | ||
"type": "object", | ||
"properties": { | ||
"cat": { | ||
"type": "string", | ||
"enum": [ | ||
"foo" | ||
] | ||
}, | ||
"name": { | ||
"type": "string" | ||
} | ||
} | ||
}, | ||
"ext_schemas_Bar": { | ||
"type": "object", | ||
"properties": { | ||
"cat": { | ||
"type": "string", | ||
"enum": [ | ||
"bar" | ||
] | ||
}, | ||
"other": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
schemas: | ||
Foo: | ||
type: object | ||
properties: | ||
cat: | ||
type: string | ||
enum: [ "foo" ] | ||
name: | ||
type: string | ||
Bar: | ||
type: object | ||
properties: | ||
cat: | ||
type: string | ||
enum: [ "bar" ] | ||
other: | ||
type: string |