s-knibbs / dataclasses-jsonschema

JSON schema generation from dataclasses
MIT License
166 stars 38 forks source link

Don't include empty definitions object in generated schema #59

Closed s-knibbs closed 5 years ago

s-knibbs commented 5 years ago

A minor issue, but when generating a schema from a dataclass that references no other dataclasses an empty definitions object is generated. This should be omitted instead. Example:

@dataclass
class Point(JsonSchemaMixin):
    x: int
    y: int

Current generated schema:

{
  "type": "object",
  "required": [
    "x",
    "y"
  ],
  "properties": {
    "x": {
      "type": "integer"
    },
    "y": {
      "type": "integer"
    }
  },
  "description": "Point(x: int, y: int)",
  "definitions": {},
  "$schema": "http://json-schema.org/draft-06/schema#"
}

Expected schema:

{
  "type": "object",
  "required": [
    "x",
    "y"
  ],
  "properties": {
    "x": {
      "type": "integer"
    },
    "y": {
      "type": "integer"
    }
  },
  "description": "Point(x: int, y: int)",
  "$schema": "http://json-schema.org/draft-06/schema#"
}