Giter Site home page Giter Site logo

gtad's People

Contributors

jjjt-hub avatar kitsuneral avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gtad's Issues

Proper scope for local schema definitions

As a part of #16 implementation, a case should be supported when there are two schema definitions with the same title. Keeping them both on the top level leads to a name conflict while only keeping the first definition will fails if the two define different structures (and we cannot guarantee them being the same structure, even though the Matrix Swagger seems to be good enough in that respect).

Support content-repo.yaml

content-repo.yaml defines headers that should be present in the request and the response. The request headers make it to the output but hyphens are not erased from their names, resulting in invalid identifiers. The response headers just don't make it to Printer.
Also, content-repo is the only file using content type different from application/json, meaning that plain byte stream will be used for the result.
There may probably be other caveats.

Types map adds ^ and $ to its regexes

std::regex_match checks that the entire string matches the regex. This in particular means that // doesn't work for "everything else", it only matches an empty string, which is not intuitive.

Recurring data definitions land in improper directories

As of ccfe0d8, if there's a reference inside a file to another file, that other one is correctly found and parsed by Printer receives wrong directory to output the respective result to. This leads to rather (un)funny things like some definitions landing in jobs/generated, while their proper place would be in jobs/generated/definitions, etc.

Support titles and deeper parsing of schemas

So far anything more complex than a flat list of properties is converted to an opaque object (matching QJsonObject in Qt), both for parameters and for response properties. Also, schema title attribute is completely skipped though it could serve as a type name.

Error when building

[ 82%] Building CXX object CMakeFiles/gtad.dir/analyzer.cpp.o
/home/adam/repos/gtad/analyzer.cpp:25:22: error: 'placeholders' is not a namespace-name
 using namespace std::placeholders;
                      ^~~~~~~~~~~~
/home/adam/repos/gtad/analyzer.cpp:25:34: error: expected namespace-name before ';' token
 using namespace std::placeholders;
                                  ^
make[2]: *** [CMakeFiles/gtad.dir/build.make:89: CMakeFiles/gtad.dir/analyzer.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/gtad.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

Again, not familiar with normal cpp toolchain. If more info is needed than above, I can run commands to get it.

Allow to substitute parameter/`VarDecl` names

This is a better fix for a problem with parameters which names coincide with reserved words of a target language. For C++ and Matrix CS API, such conflicting names are signed, unsigned and default (default is most conflicting because in addition it nearly-clashes with OpenAPI's own default attribute that stores a default value for a certain parameter). A workaround has been to pre-substitute all such words in YAML; however, its well-known drawback (it replaces all such words, regardless of the place) backfired when GTAD gained support for (you guessed it) default values. Providing a way to substituting parameter names (and only them) somewhere around env (but under a separate config section) looks a better alternative.

Support response structure inlining

Similar to inlineBody for request bodies, there should be inlineResponse for responses, with the same rationale - when a structure is included (via $ref) from another file, the fact of inclusion should be completely transparent for the actual marshalling. Case in point also matches that for inlineBody: if a top-level schema is a $ref, there should be a top-level data structure representing this schema in the code; however, this data structure is entirely absent in the actual JSON, so should be explicitly rolled-up from actual JSON top-level data.

Allow to use different templates for models and operations

Right now GTAD doesn't distinguish between templates for models and for operations. This leads to each template having a big {{#models}} section followed by a big {{#operations}} section with very little common part. Instead of a single array, mustache/templates should become a map with model and operation being arrays of template file names.

Avoid processing same structures over and over

As of now, if the same data structure ($refed, e.g.) is encountered several times in the API description it gets parsed, and has code generated, every time anew. So far GTAD generates the same code for externally ($ref) defined schemas; however, if In/Out direction is applied to those schemas, things may get broken (imagine the same structure $refed both from request and from response).

The proper way to fix it would probably be to accumulate all data models in memory before dumping them all to Printer. This will enable extending those models as they get encountered in the API description (e.g. add Out to already known In direction).

enumerations support

Support analysing enum attributes in parameter descriptions and replacing strings with enumeration types. To stay neutral to the target language this might need introducing one more renderer in gtad.yaml syntax.

Parse "consumes" node

GTAD already parses "produces" OpenAPI key, "consumes" should be done in a similar way.

Write a README.md

Right now the project is completely unusable from outside because there is no documentation regarding even how to run it, let alone example config files, templates etc.

Support Matrix CS API 0.4.0

The new release of Matrix CS API has schemas that are compositions of another type and an additional field in the body schema. The following problems should be solved:

  • A combination of $ref and a non-$ref entity under allOf. In the particular cases of CS API it can be remedied by pulling properties of the inner object to the level of the main structure (and that's actually a more transparent description). However, not all (theoretical) cases can be resolved that way, so GTAD has to learn that allOf is allowed to have non-$ref entries.
  • Even if the properties are pulled as described above, GTAD fails to flatten the request body schema, instead creating a type definition that depends on itself (corresponding to struct Type : Type in C++). It should further pull out properties out of the schema and turn them into individual parameters of the request.

Doesn't mark an in schema as an out one too

Case in point: search.yaml where SearchJob::Result (the output schema) uses SearchJob::EventContext (the input schema). EventContext is not marked as out, leading to the missing FromJson converter.

TypeUsage -> TypeDefinition+TypeUsage

Translator::mapType() now has to make a copy of TypeUsage (with all its attributes), which is very inefficient given how many times types should be resolved while analysing API specs. The situation can be solved easily for non-parameterised types by pointing to the type instead of copying. For parameterised types it's more complicated since that pointer would need to be accompanied with type parameters. As noted in the comment in Translator::mapType(), TypeUsage should become a "smart handle" to an instance of a newly-made TypeDefinition structure that would own all the stuff TypeUsage now has, except innerTypes.

Don't alias types

There was an idea that trivial schemas should still be named if they are named in the API spec. That idea turned to be ineffective, as all such aliases are rather misleading than hinting. So remove this.

GTAD ignores $refs (even those not overridden)

As of 0.5, GTAD ignores $references unless the catch-all block in object is written in a very specific way excluding $ref'ed file name patterns. In case of a usual // it just intercepts such objects and uses a generic object (such as QJsonObject) for them. The proper way would be to distinguish between objects defined inline and $refs, having separate type maps for them (with $ref possibly falling back to object).

Proper processing of additionalProperties

Turns out that additionalProperties and properties can legitimately coexist, as the case of definitions/auth_data.yaml shows. GTAD only processes additionalProperties when there are no base types or other properties, which is incorrect (even overriding all properties with a single structure for additionalProperties would be better).

Update: there's more to this issue - GTAD doesn't process additionalProperties if they appear on the top level of a standalone schema (such as freshly added application-service/protocol_metadata.yaml).

Support body in response

As of f3d4f3b, GTAD can parse object schemas, including those in the response. Next steps are:

  • Move the response structure from CallClass to Call in the model (thereby accepting cases when the two calls having the same name might have different response types - but having two calls with the same name is forbidden by the Swagger spec, anyway).
  • Remove the code that checks the response for non-triviality and move the whole block that analyzes the result schema after a Call object creation.
  • In Printer, use the (now useable) response structure to fill in correct context values
  • In libqmatrixclient code, use the context values (the current blocks of code refer to variables that don't exist in Swagger's intermediate JSON).

Support non-trivial responses with no body

No body error responses do not require any special treatment other than storing the HTTP code (which should normally be outside of GTAD-generated code anyway). So probably it boils down to parsing those codes without digging into returned schemas (a matter of #32).

The order of imports is unstable

Since the list of imports is internally an unordered_set, the order of entries in it may change between runs, even if input files are intact. This breaks build reproducibility and adds unnecessary diffs if generated files are kept under version control.

Support default values

Default parameter values have been ignored in API files so far; they should be taken and inserted into the model. Respectively, Printer should gain ability to dump default values so that Mustache templates could adorn them with additional text if necessary. This implies introducing type attributes that can work as Mustache partials - similar to what env variables already do.

Multitype support

Multitype is used in presence.yaml of Matrix CS API; having a QJsonObject instead of QVariant (or even a QString but we'll need parameter special-casing for that) in that particular case is not even correct because it's actually either a string or nothing; not an object.

Add necessity of cloning submodules for building gtad

Not being super familiar with norms of cpp development, it took me a bit of time to figure out that the errors cmake was spitting at me were because I hadn't cloned the project's submodules. Brief line in README would clarify this for people in the future.

There's no way to stop inheriting higher-level values down to inner structures

Especially aggravating with doc-comments that are stored in description GTAD-list objects; if an inner entity doesn't have its own description, the upper-level description takes the place of the absentee, which is really not what's wanted. A fix would probably involve removing the actual list from the hierarchy to some wrapper section, so that trying to get to it on the lower level would stop on checking out an existing-but-empty object instead of no-object.

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.