Skip to content
This repository has been archived by the owner on Aug 19, 2023. It is now read-only.

Invalid OpenAPI for Set[Any] #127

Open
ZdenekM opened this issue Jan 13, 2020 · 0 comments
Open

Invalid OpenAPI for Set[Any] #127

ZdenekM opened this issue Jan 13, 2020 · 0 comments

Comments

@ZdenekM
Copy link

ZdenekM commented Jan 13, 2020

The following example:

from dataclasses import dataclass
from typing import Set, Any
from dataclasses_jsonschema import JsonSchemaMixin
from apispec import APISpec  # type: ignore
from apispec_webframeworks.flask import FlaskPlugin  # type: ignore
from dataclasses_jsonschema.apispec import DataclassesPlugin


@dataclass
class ArbitraryValues(JsonSchemaMixin):

    arbitrary_value: Any
    set_of_arbitrary_values: Set[Any]


spec = APISpec(
    title="Test",
    version="1.0.0",
    openapi_version="3.0.2",
    plugins=[FlaskPlugin(), DataclassesPlugin()],
)

spec.components.schema(ArbitraryValues.__name__, schema=ArbitraryValues)
print(spec.to_yaml())

generates invalid OpenAPI:

components:
  schemas:
    ArbitraryValues:
      description: 'ArbitraryValues(arbitrary_value: Any, set_of_arbitrary_values:
        Set[Any])'
      properties:
        arbitrary_value: {}
        set_of_arbitrary_values:
          type: array
          uniqueItems: true
      required:
      - arbitrary_value
      - set_of_arbitrary_values
      type: object
info:
  title: Test
  version: 1.0.0
openapi: 3.0.2
paths: {}

The field items is missing for set_of_arbitrary_values. It should be like this:

set_of_arbitrary_values:
          type: array
          uniqueItems: true
          items:
              {}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant