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

PSADv1: specify the content body using "mediatype", not "resource" #103

Open
automatthew opened this issue May 18, 2017 · 3 comments
Open
Assignees

Comments

@automatthew
Copy link
Contributor

automatthew commented May 18, 2017

The first round of work, for expedience, specifies the schema for the request or response body using a reference to a key in the dictionary of JSON Schemas.

resources:
  blurbs:
    path: /blurbs
    description: "Virtual collection of blurbs"
    methods:
      POST:
        signatures:
          request:
            resource: blurb
          response:
            status: [201, 400]
schema:
  blurb:
    $schema: "http://json-schema.org/draft-04/schema"
    title: Blurb
    type: object
    properties:
      content:
        type: string
      expiration:
        type: string
        format: date-time

Using a media-type is preferable, and part of the original redesign for PSAD.

To make this work, each schema in the API Description must declare a "mediaType" at its top level. Unfortunately, the API Gateway JSON Schema validator is slightly non-compliant, disallowing unknown keywords. We can handle this by stripping the "mediaType" property from the schema definition we use to define API Gateway Models in the CloFoTemp.

This addition will not break existing apps, which may transition to using mediatype instead of resource in the api.yaml at will.

@dyoder
Copy link
Member

dyoder commented May 18, 2017

Maybe the indirection is kind of nice? We'd still need to add mediaType to the schema, but we'd look it up when constructing the API GW template. It's always been a little bit annoying to have to put the full media type in the signature. The only trouble with this is versioning, since the media type may include a version attribute. But we could introduce a version attribute in the signature.

Another possibility would be to construct the media type via convention, ex:

application/vnd.{{vendor}}.{{resource}};charset={{charset}};version={{version}}

where vendor and charset are perhaps set in sky.yaml (charset could default to utf-8).

That is, rather than burden the developer with figuring this out, we just do the right thing by default. Later, we could (if people demand it), add a mediaType attribute either to the schema or to the signature to override the convention.

Also, technically, we will want eventually to allow for an arrays of types in the signature. Or perhaps an array of versions? So we'd end up with something like this:

resources:
  blurbs:
    path: /blurbs
    description: "Virtual collection of blurbs"
    methods:
      POST:
        signatures:
          request:
            resource: blurb
            # this is the part that's changed
            versions: [1, 2]
          response:
            status: [201, 400]
schema:
  blurb:
    $schema: "http://json-schema.org/draft-04/schema"
    title: Blurb
    type: object
    properties:
      content:
        type: string
      expiration:
        type: string
        format: date-time

@automatthew
Copy link
Contributor Author

We should definitely have multiple mediatypes allowed for request/response bodies.

In addition to having signatures.request.mediatype, we can have signatures.request.schema, with the value being a JSON Pointer to a particular schema, either relative to the one we define, or fully specified as a URL:

signatures:
  request:
    schema:
      - "#/blurb"
      - "https://schema.blurb9.com/v1#blurb"

@dyoder
Copy link
Member

dyoder commented May 18, 2017

@automatthew I'm unsure if you intended this or if we're talking past each other, but that's more or less the opposite direction of what I'm suggesting.

Can't we incorporate external schemas by reference? That is, in the schema itself.

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