dataclasses-jsonschema icon indicating copy to clipboard operation
dataclasses-jsonschema copied to clipboard

Invalid OpenAPI for Set[Any]

Open ZdenekM opened this issue 4 years ago • 0 comments

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:
              {}

ZdenekM avatar Jan 13 '20 08:01 ZdenekM