question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support generating models from json-schemas defined in multiple files

See original GitHub issue

Is your feature request related to a problem? Please describe. Now the tool cli API supports only single file as input. I’d suggest to extend it to have directory as as option. This would help with generating models from json-schema (or may be even from other formats as well). For example, let’s have the following schemas (see below).

Since the tool doesn’t support directory as input I make a separate CLI call for both file. In that case the output would have:

  • model generated from object.json for Object
  • model generated from object.json for referenced Metadata
  • model generated from metadata.json

Even more, if we have 2 and more files, which, like object.json refer to the same external reference, we will have copy of the model in every output file.

// object.json
{
  "$schema": "http://json-schema.org/schema#",
  "type": "object",
  "title": "Object",
  "properties": {
    "metadata": {
      "$ref": "metadata.json#/"
    }
  },
  "required": [
    "metadata",
  ]
}

// another file in the same dir
{
  "$schema": "http://json-schema.org/schema#",
  "type": "object",
  "title": "Object",
  "properties": {
    "somefield": {
      "type": "integer"
    }
  },
  "required": [
    "metadata",
  ]
}

Describe the solution you’d like In the described case I would like to avoid duplicated models output for the references.

Describe alternatives you’ve considered May be, another alternative is to recursively call the datamodel-codegen in case of reference to the external file (then even if we had made few calls to generate the same reference from different referees we would just override the previous result in a separate file, instead of generating inline pydantic model-duplicate).

Additional context Add any other context or screenshots about the feature request here.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:37 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
themmescommented, Mar 2, 2021

@koxudaxi Thanks a lot for the heads up, thats very kind 🙏 ! I’ll make the changes like you suggested and will test it soon with this new version.

2reactions
themmescommented, Dec 17, 2020

That is amazing, works really well now. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to manage multiple JSON schema files? - Stack Overflow
In JSON Schemas, you can either put a schema per file and then access them using their URL (where you stored them), or...
Read more >
Implementations - JSON Schema
Elm. json-schema-to-elm - generates Elm types, JSON decoders+encoders, and fuzz tests from one or more JSON Schema files, using dragonwasrobot/json_schema ...
Read more >
Data Models (Schemas) - Swagger
The data types are described using a Schema object. To learn how to model various data types, see the following topics: Data Types....
Read more >
Generating Schemas - Json.NET
Json.NET Schema supports automatically generating JSON Schemas for .NET types using the JSchemaGenerator object. The generator has a number of options for ...
Read more >
Defining the schema of your JSON file - 8.0 - Talend Help Center
Available in... Open Studio for Big Data Open Studio for Data Integration Open Studio for ESB About this task In this step, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found