Skip to content

Consider specifying /mmds get schema as string rather than object #1229

@samuelkarp

Description

@samuelkarp

Hello!

Currently the MMDS get operation is defined as follows:

  /mmds:
    #  ...snip...
    get:
      summary: Get the MMDS data store.
      responses:
        200:
          description: The MMDS data store JSON.
          schema:
            type: object
        400:
          description: Cannot get the MMDS data store due to bad input.
          schema:
            $ref: "#/definitions/Error"
        default:
          description: Internal server error
          schema:
            $ref: "#/definitions/Error"

The schema is defined as object, which is parallel to the schema of the put and patch operations as well. In the Firecracker SDK for Go, we've received a pull request to add a GetMetadata method to retrieve the metadata from the MMDS. However, the definition of the schema as object (and the way that go-openapi generates a client) makes that difficult to work with.

When object is defined, our Swagger client generator gives us an interface{}, which is Go's equivalent of a void pointer; we then need figure out some way of converting that to a useful value. One mechanism is to implement dynamic type discovery, which is a lot of boilerplate and error-prone code. Another is to send this back through another serialization-deserialization round-trip to use Go's built-in JSON decoding, but that will be inefficient especially for large objects. Or there are other approaches that involve digging beneath the Swagger client library's abstractions.

Would you be willing to change this to a string (and format: binary) instead of object? If this were defined as a string, we would get the serialized data back and can deserialize it ourselves instead of needing these workarounds.

If this isn't a change you'd be willing to make, we do have some options:

  1. Dynamic type discovery
  2. Reserialize-deserialize round-trip
  3. Patch the swagger spec ourselves
  4. Implement a separate Client with a separate runtime.ClientResponseReader just for this operation

But these approaches are all more complicated, and (though I haven't looked) I suspect that other Swagger client generators in other programming languages will have similar challenges with a returned object.

Thanks,
Sam

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions