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

Alternative Schema and Custom Security Schemes #1736

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 87 additions & 2 deletions versions/3.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,7 @@ Field Name | Type | Description
<a name="schemaExternalDocs"></a>externalDocs | [External Documentation Object](#externalDocumentationObject) | Additional external documentation for this schema.
<a name="schemaExample"></a>example | Any | A free-form property to include an example of an instance for this schema. To represent examples that cannot be naturally represented in JSON or YAML, a string value can be used to contain the example with escaping where necessary.
<a name="schemaDeprecated"></a> deprecated | `boolean` | Specifies that a schema is deprecated and SHOULD be transitioned out of usage. Default value is `false`.
<a name="alternativeSchema"></a>alternativeSchema | [Alternative Schema Object](#alternativeSchemaObject) | An external schema that participates in the validation of content along with other schema keywords.

This object MAY be extended with [Specification Extensions](#specificationExtensions).

Expand Down Expand Up @@ -3162,25 +3163,109 @@ animals:
</aliens>
```

#### <a name="alternativeSchemaObject"></a>Alternative Schema Object

This object makes it possible to reference an external file that contains a schema that does not follow the OAS specification. If tooling does not support the ``type``, tooling MUST consider the content valid but SHOULD provide a warning that the alternative schema was not processed.

##### Fixed Fields
Field Name | Type | Description
---|:---:|---
<a name="alternativeSchemaType"></a>type | `string` | **REQUIRED**. The value MUST match one of the values identified in the alternative Schema Registry.
<a name="alternativeSchemaLocation"></a>location | `url` | **REQUIRED**. This is a absolute or relative reference to an external resource containing a schema of a known type. This reference may contain a fragment identifier to reference only a subset of an external document.

This object MAY be extended with [Specification Extensions](#specificationExtensions).

##### Examples

Minimalist usage of alternative schema:

```yaml
schema:
alternativeSchema:
type: jsonSchema
location: ./real-jsonschema.json
```

Combination of OAS schema and alternative:

```yaml
schema:
type: object
nullable: true
alternativeSchema:
type: jsonSchema
location: ./real-jsonschema.json
```

Multiple different versions of alternative schema:

```yaml
schema:
anyOf:
- alternativeSchema:
type: jsonSchema
location: ./real-jsonschema-08.json
- alternativeSchema:
type: jsonSchema
location: ./real-jsonschema-07.json
```

Combined alternative schemas:

```yaml
schema:
allOf:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a allOf that has firstOf semantics? Should this be a blocker for shipping alternative-schema?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x-oas-draft-firstOfPleaseDontBugJSONSchemaAboutThis 😜

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted on today's call (for the benefit of those not present), I think (pending the resolution of other procedural concerns), we should move ahead with alternativeSchema for the many use cases that do not require firstOf semantics, and consider x-oas-draft-firstOf to get more feedback on that use case. Particularly how prevalent it is in practice.

- alternativeSchema:
type: xmlSchema
location: ./xmlSchema.xsd
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- alternativeSchema:
type: schematron
location: ./schema.sch
```

Mixed OAS schema and alternative schema:

```yaml
schema:
type: array
items:
alternativeSchema:
type: jsonSchema
location: ./real-jsonschema.json
```

##### Alternative Schema Registry

It is important that there is a common understanding of the values which can be used to populate the alterative schema "type" property. An registry of alternative schema types is hosted at [https://spec.openapis.org/registries/alternative-schema](https://spec.openapis.org/registries/alternative-schema). This register serves as a controlled vocabulary which should be used to populate the "type" property. The Inital contents of the registry include:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
It is important that there is a common understanding of the values which can be used to populate the alterative schema "type" property. An registry of alternative schema types is hosted at [https://spec.openapis.org/registries/alternative-schema](https://spec.openapis.org/registries/alternative-schema). This register serves as a controlled vocabulary which should be used to populate the "type" property. The Inital contents of the registry include:
It is important that there is a common understanding of the values which can be used to populate the alternative schema "type" property. A registry of alternative schema types is hosted at [https://spec.openapis.org/registries/alternative-schema](https://spec.openapis.org/registries/alternative-schema). This register serves as a controlled vocabulary which should be used to populate the "type" property. The Initial contents of the registry include:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also "This register serves" -> "This registry serves"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: link is dead for me

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fenollp yeah, I think the expectation is that that registry will exist by the time OAS 3.1 is published, but it has not been set up yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fenollp you can substitute spec.mermade.org.uk for spec.openapis.org in those urls to get an idea for how the registry might look (framework is an approved proof-of-concept, but the content is purely illustrative).


Name | Link | Description
---|:---:|---
<a name="jsonSchemaType"></a>jsonSchema | `https://spec.openapis.org/registries/alternative-schema#jsonSchema` | JSON schema documents
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If next OAS will use jsonSchema this could be removed, right?

<a name="xmlSchemaType"></a>xsdSchema | `https://spec.openapis.org/registries/alternative-schema#xsdSchema` | XML schema documents
<a name="schematronType"></a>schematron | `https://spec.openapis.org/registries/alternative-schema#schematron` | XML schematron rule sets

#### <a name="securitySchemeObject"></a>Security Scheme Object

Defines a security scheme that can be used by the operations.
Supported schemes are HTTP authentication, an API key (either as a header, a cookie parameter or as a query parameter), OAuth2's common flows (implicit, password, application and access code) as defined in [RFC6749](https://tools.ietf.org/html/rfc6749), and [OpenID Connect Discovery](https://tools.ietf.org/html/draft-ietf-oauth-discovery-06).
Supported schemes are HTTP authentication, an API key (either as a header, a cookie parameter or as a query parameter), OAuth2's common flows (implicit, password, application and access code) as defined in [RFC6749](https://tools.ietf.org/html/rfc6749), and [OpenID Connect Discovery](https://tools.ietf.org/html/draft-ietf-oauth-discovery-06). Additional "custom" schemes can be described but the level of tool support will be limited.

##### Fixed Fields
Field Name | Type | Applies To | Description
---|:---:|---|---
<a name="securitySchemeType"></a>type | `string` | Any | **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`.
<a name="securitySchemeType"></a>type | `string` | Any | **REQUIRED**. The type of the security scheme. Valid values are `"apiKey"`, `"http"`, `"oauth2"`, `"openIdConnect"`, `"custom"`.
<a name="securitySchemeDescription"></a>description | `string` | Any | A short description for security scheme. [CommonMark syntax](http://spec.commonmark.org/) MAY be used for rich text representation.
<a name="securitySchemeName"></a>name | `string` | `apiKey` | **REQUIRED**. The name of the header, query or cookie parameter to be used.
<a name="securitySchemeIn"></a>in | `string` | `apiKey` | **REQUIRED**. The location of the API key. Valid values are `"query"`, `"header"` or `"cookie"`.
<a name="securitySchemeScheme"></a>scheme | `string` | `http` | **REQUIRED**. The name of the HTTP Authorization scheme to be used in the [Authorization header as defined in RFC7235](https://tools.ietf.org/html/rfc7235#section-5.1).
<a name="securitySchemeBearerFormat"></a>bearerFormat | `string` | `http` (`"bearer"`) | A hint to the client to identify how the bearer token is formatted. Bearer tokens are usually generated by an authorization server, so this information is primarily for documentation purposes.
<a name="securitySchemeFlows"></a>flows | [OAuth Flows Object](#oauthFlowsObject) | `oauth2` | **REQUIRED**. An object containing configuration information for the flow types supported.
<a name="securitySchemeOpenIdConnectUrl"></a>openIdConnectUrl | `string` | `openIdConnect` | **REQUIRED**. OpenId Connect URL to discover OAuth2 configuration values. This MUST be in the form of a URL.
<a name="customType"></a>extensionType | `string` | `custom` | **REQUIRED**. When the security scheme type is custom, the customType field provides an identifier for the type of custom scheme. The valid values for this field are not controlled. Use of a well known identifier or MIME Type is encouraged to avoid collisions.

This object MAY be extended with [Specification Extensions](#specificationExtensions).

Custom schemes may be processed in much the same manner as extensions. Implementations shall accept "custom" as a valid value for the securitySchemeType field. They shall also validate that the customType field is present and populated when the value of securitySchemeType is "custom". Any additional data needed to describe the custom schema shall be provided using [Specification Extensions](#specificationExtensions).

##### Security Scheme Object Example

###### Basic Authentication Sample
Expand Down