Git Product home page Git Product logo

Comments (6)

liamnichols avatar liamnichols commented on May 27, 2024 1

I had a go at doing this, but I found a bug in Yams that is a slight blocker (it caused one of the specs that decodes a json configuration to fail):

Other than the empty string/optional issue though, Yams has been pretty good at handling our 31,500 line OpenAPI schema in JSON format, we've just been renaming it to .yml (so that CreateAPI uses Yams and preserves the ordering) but not converting it from JSON.

from createapi.

kean avatar kean commented on May 27, 2024

Unfortunately, that seems to be the case. It's recommended to use YAML. OpenAPIKit uses ordered dictionaries to preserve the order of the keys when it can (YAML).

To convert, you can use Swagger Editor. See File / Convert and save as JSON.

There is also a CreateAPI option to sort properties alphabetically which is disabled by default:

entities:
  isSortingPropertiesAlphabetically: true

from createapi.

PhilipTrauner avatar PhilipTrauner commented on May 27, 2024

The primary objective of this revision is to bring YAML into compliance with JSON as an official subset.

YAML 1.2 Specification (2009)

It should be perfectly valid to use YAMLDecoder for json documents.
This of course hinges on how closely Yams follows the spec.

I didn't run into any issues with the OpenAPI specs I tried (two small internal ones), but that feels like too small of a sample size to conclusively rule out any nasty edge cases.

from createapi.

PhilipTrauner avatar PhilipTrauner commented on May 27, 2024

If retaining order is important for your use-case, I recommend the Yams and FineJSON libraries for YAML and JSON respectively. Also keep in mind that JSON is entirely valid YAML and therefore you will likely get good results from Yams decoding of JSON as well (it just won't encode as valid JSON).

OpenAPIKit Documentation

Not sure if "you will likely get good results" is good enough, but I'd argue that entity generation with JSON as input should currently be considered broken, as its behavior is unexpected for anyone unfamiliar with the JSON specification.

Would you be interested in a PR that switches the JSON parser over to Yams and adds tests?
It wouldn't be necessary to check in any JSON specs, as decoding a YAML spec with Yams and consequently encoding it with JSONEncoder does retain order.

from createapi.

kean avatar kean commented on May 27, 2024

should currently be considered broke

As in the ordering, or are there more issues?

Would you be interested in a PR that switches the JSON parser over to Yams and adds tests?

Yeah, absolutely. Let's give it a try. If it resolved the ordering issue, that would be fantastic.

I have a private repo with 1KK lines of specs, but they are all YAML. I'll give you access in case you need it. It's not perfectly structured. It was initially part of this project, so I just copied it and symlinked the sources for now.

But I think adding a JSON+YAML test to this repo should be enough.

from createapi.

liamnichols avatar liamnichols commented on May 27, 2024

Fixed in 0.0.4! Thanks 🚀

from createapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.