glideapps / glideapps/quicktype

JSON Schema not parsed correctly?

Open
#1,643 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
13.9k
Forks
1.2k
Avg merge
8h 53m
Merged PRs (30d)
369

Description

Hi all,

right now I'm facing a problem that a some what complicated (as far as I think) JSON Schema is not parsed correctly.
(Please find schema in attached file [electrical.json.zip](https://github.com/quicktype/quicktype/files/5918006/electrical.json.zip) )

I would like to have swift code generated from that schema, but the error happens in other languages as well.
The problem with this schema is, that the types of the properties like 'alternators', 'batteries' and so on are declared in the schema, but not recognized by the generator, I think.

As I know, that most of the time the error is in front of the computer, I verified with several tools that the schema is valid and had no evidence of an error in this chapter.

This is part of the code generated:

```swift
/// Schema describing the electrical child-object of a Vessel.
// MARK: - Electrical
struct Electrical: Codable {
/// AC buses
let ac: JSONAny?
/// Data about an Alternator charging device
let alternators: JSONAny?
/// Data about the vessel's batteries
let batteries: JSONAny?
/// Data about AC sourced battery charger
let chargers: JSONAny?
/// Data about the Inverter that has both DC and AC qualities
let inverters: JSONAny?
/// Data about Solar charging device(s)
let solar: JSONAny?

enum CodingKeys: String, CodingKey {
case ac = "ac"
case alternators = "alternators"
case batteries = "batteries"
case chargers = "chargers"
case inverters = "inverters"
case solar = "solar"
}
}
```

I apologize in advance if the mistake is on my side and wasted your time.

Cheers
Frank

PS:
I used the online version as well as the command line tool. Because of the references in the schema the executed command looks like:

```
quicktype --additional-schema definitions.json --additional-schema groups/communication.json
--additional-schema groups/environment.json --additional-schema groups/navigation.json
--additional-schema groups/notifications.json --additional-schema groups/design.json
--additional-schema groups/sensors.json --additional-schema groups/resources.json
--additional-schema groups/sources.json --additional-schema vessel.json
--additional-schema aircraft.json --additional-schema aton.json --additional-schema sar.json
--additional-schema external/geojson/geometry.json --additional-schema external/geojson/geojson.json
--additional-schema external/geojson/crs.json --additional-schema external/geojson/bbox.json
--additional-schema groups/electrical.json --additional-schema groups/performance.json
--additional-schema groups/propulsion.json --additional-schema groups/sails.json
--additional-schema groups/steering.json --additional-schema groups/tanks.json
--additional-schema aircraft.json --additional-schema aton.json --additional-schema definitions.json
--additional-schema delta.json --additional-schema discovery.json --additional-schema sar.json
--additional-schema signalk.json --additional-schema vessel.json
--swift-5-support --multi-file-output -l swift -s schema
--src groups/electrical.json --out src/Electrical.swift
```

The complete generated file looks like:
[Electrical.swift.zip](https://github.com/quicktype/quicktype/files/5918094/Electrical.swift.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.