Skip to content

Link to Multiple Items of Array #1452

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

Closed
tgockel opened this issue Jan 5, 2018 · 2 comments
Closed

Link to Multiple Items of Array #1452

tgockel opened this issue Jan 5, 2018 · 2 comments

Comments

@tgockel
Copy link

tgockel commented Jan 5, 2018

There is an API with two operations:

  • GET /foo/{fooId}: Get some object, given its ID.
  • POST /foo: Create multiple objects and return an array of IDs for the newly-created objects.

The OpenAPI specification of this is:

openapi: "3.0.1"

info:
  description: Foo all the way!
  version: "1.0"
  title: "Foo API"

paths:
  /foo/{fooId}:
    get:
      operationId: getFoo
      parameters:
        - name: fooId
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Got the Foo.
          content:
            'application/json':
              schema:
                type: object
                properties:
                  fooId:
                    type: integer
                  name:
                    type: string
  /foo:
    post:
      operationId: createFoos
      description: "Create some Foos"
      requestBody:
        content:
          'application/json':
            schema:
              type: array
              items:
                type: string
      responses:
        201:
          description: Created the Foos.
          content:
            'application/json':
              schema:
                type: object
                properties:
                  fooIds:
                    type: array
                    items:
                      type: integer
          links:
            getFoo:
              operationId: getFoo
              parameters:
                fooId:
                  '$response.body#/fooIds'

The problem is the links specification of the createFoos operation is wrong. As specified, a response to POST /foo of:

{
  "fooIds": [1, 2, 3]
}

implies the proper way to fetch the created objects would be to GET /foo/[1,2,3], which is quite incorrect. I would like to inform this system that the contents of the array are the linked operation, not the array itself. The is no mechanism to do this in OpenAPI, as JSON Pointers do not appear to support doing what I want here (it is meant to point to a single object rather than a pattern of objects).


Not to be too prescriptive, since I'm only a user of OpenAPI, but JSONPath is intended for this sort of thing. The equivalent specification would be '$response.body#$.fooIds[*]'. That said, there's no obvious way to make the switch without breaking compatibility :-(

@MikeRalphson
Copy link
Member

See also #1327

@tgockel
Copy link
Author

tgockel commented Jan 5, 2018

Ah yes -- that is definitely the same underlying issue. Closing this due to it's redundancy.

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

2 participants