Skip to content

RecipesPage

Jens Finkhaeuser edited this page Jun 14, 2017 · 1 revision

Numeric Response Codes

The Amazon API Gateway tools tend to create Swagger specs that are, strictly speaking, invalid. The main sticking point is whether or not to allow numeric response codes (see #5), e.g.

paths:
  /test:
    post:
      responses:
        200: #<---
          description: foo

Numeric response codes are intuitive to write, of course. Unfortunately, here YAML and JSON specs drift apart. YAML allows all sorts of key types (even complex objects), whereas JSON requires strictly string keys.

The Swagger specs provide examples in YAML, but include JSON pointers/references, both in YAML and in JSON. Additionally, they provide a JSON schema for validation.

All of which means that, strictly speaking, Swagger only allows the subset of YAML that would also be valid JSON. And that means no numeric keys, ever.

To get around this issue, prance has a strict keyword option for its parsers. It defaults to True, but if False, the parsers stringify all keys in the specs. That might have unintended side effects, but it's by far the simplest measure for accepting numeric response codes.

parser = ResolvingParser('path/to/my/specs.yaml', strict = False)
Clone this wiki locally