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

Link to schema from description etc #1268

Open
henhal opened this issue May 24, 2020 · 0 comments
Open

Link to schema from description etc #1268

henhal opened this issue May 24, 2020 · 0 comments

Comments

@henhal
Copy link

henhal commented May 24, 2020

Is it possible to create links and/or embed other schemas in the description of a property?
I saw that in #681, support for <SchemaDefinition> tags was added, but apparently only to tag descriptions?

My use case is this: The API has multiple instances of encrypted data containers. In encrypted form, the data always has the same structure (containing a public key fingerprint, an ephemeral key encrypted with said public key, etc - standard hybrid encryption), so this is defined in a re-used schema obviously. But it's also useful to describe the schema for the raw/source JSON data once the encrypted data container is decrypted, so API consumers know how to parse the decrypted data.

Example:

EncryptedData:
  description: Generic encrypted representation of arbitrary data
  type: object
  properties:
    data:
      type: string
      format: byte
      description: The data encrypted with the ephemeral key
    encryptedKey:
      type: string
      description: The ephemeral AES key, encrypted with the public RSA key
    publicKeyFingerprint:
      type: string
      description: The fingerprint of the public RSA key

Some.SourceData:
  type: object
  description: Some data we want to encrypt
  properties:
    foo: {type: string}
    bar: {type: integer}

Some.Request:
  type: object
  properties:
    encryptedData:
      allOf:
        - description: Encrypted data container containing the encrypted representation of a `Some.SourceData` object
        - $ref: '#/EncryptedData'

In this case, Some.Request contains an encrypted container of a Some.SourceData object (so you'd get the raw object from something like JSON.parse(decrypt(req.body.encryptedData))).

In my spec, I've included the schemas for the decrypted raw representation as well, but it will be an orphaned object without any references to it, since it's not actually part of any other schema or API, it's only there to describe the schema of another object after it's been decrypted (or before it's been encrypted).
To at least include it in my documentation, it would be nice if I could link to it so that when viewing the Some.Request operation, I can expand it and find that encryptedData is of type EncryptedData but in decrypted form it'll be a Some.SourceData.

I think that this would be possible if <SchemaDefinition> were supported on any description element, but maybe that makes the layout too complex? Is there any other way to link one schema description to another, or in any other way achieve what I'm after?

Or should I consider the schema of decoded/decrypted objects separate entities and leave them out of my API altogether? It seems reasonablethat a server implementing this API would get a Some.Request request, validate that the body matches the schema, i.e., that encryptedData is valid, then decrypt encryptedData, parse it into a object, and then validate it using the schema of the raw data.

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

No branches or pull requests

1 participant