Get JSON object before sent to template engine from openapi-generator? - openapi-generator

I am looking for a way to get the object generated from an openapi file via openapi-generate before it gets sent to the template engine.
By this i mean, the openapi-generator must 1st generate a big object to be passed to the moustache tpl engine (containing models, interfaces, request/response objects etc etc)... how can I get hold of this object?

Related

How can I serialize and deserialize a private type?

I'm working with the GNAT.OS_Lib module to implement a process manager for Linux. I'm using the subprograms in that module to spawn processes and get back PIDs, and now I want to save those PIDs to a file so they can be retrieved later to kill the process, get its status, etc. The problem is, the Process_Id type is private:
type Process_Id is private; -- s-os_lib.ads, line 743
The module provides a Pid_To_Integer function, but not the inverse. How can I serialize and deserialize Process_Ids?
Study section K.2 "Language Defined Attributes" in the Ada Language Reference Manual http://www.ada-auth.org/standards/12rm/html/RM-K-2.html
The attributes to study are S'Read, S'Write.
Your file must be created as a stream file. The Process_Id'Write attribute will serialize and write to the stream file. The Process_Id'Read attribute will read and de-serialize the data in the file.
If S'Read and S'Write do not work for you because of the nature of a compound type you should use the S'Input and S'Output attributes, which will read and write any bounds or discriminants.
S'Input and S'Output will work correctly with all types.

API Platform custom IRI with value objects

I am currently trying to create a custom IRI for one of my entities in API Platform.
I know there is page in the documentation describing how to use a custom IRI (https://api-platform.com/docs/core/identifiers/), but I can't get it working.
My entity uses a value object for the id (currently used for IRI) and also for the name (should be used for IRI). But the values themself are priviate and scalar in the entity.
API Platform seems to get the information what should be used as the identifier, from my XML Doctrine mapping. I already tried to overwrite it by usung annotations, attributues and YAML definitions. Without luck.
The returned error reads:
preg_match(): Argument #2 ($subject) must be of type string
(at this point it receives the value object instead of the actual value)
best regards,
spigandromeda
I solved my problem.
To explain the solution, I have to dig a little into API Platform response generation.
API platform generates an IRI for every entity it returns (colelction and item operation)
it's using the Symfony router go generate the URI
all the necessary information can draw API Platform from different sources (YAML, XML, annotations, attributes)
the information include the identifier(s) defined for the entities resource
API Platform gets the value for the identifier via Symfony property accessor
because the property accessor is using getters before accessing private properties via reflection, it will return the VO
an ordinary VO cannot be used by the Symfony URL generator to create the URL
As I explained, I am using a VO for my Id as well. So I tried to figure out why it was working with the Id VO but not with the name VO.
Simple answer: the Id VO implemented the __toString method and the name VO didn't. So the solution was to let the name VO implement this method as well.
It was interesing to dig into the internal process of API Platform, but I also feel a little stupid :D

API-PLATFORM - model with object serialized to string at endpoint

I faced the problem with generating React components with api-platform-generate-crud.
Model has property that is object email.
I have serializer that make my email object a string.
API endpoint is serving string.
It works for GET & POST.
When I try to generate React components error message is
TypeError: Cannot read property '0' of undefined
Looking deeper into it, looks like that generator still see my email as object not a string.
Any idea how I can force API to 'see' email property as string not object ?
The data model you define is authoritative. Types in the Hydra documentation reflect the ones in PHP classes.
Here, the email property is of type object. If you set the related data as a string somewhere, you don't respect this contract anymore. The Hydra documentation is not in sync with the returned data.
You can change the type of the email property in the Hydra documentation by decorating the api_platform.hydra.normalizer.documentation service.
But I would recommend to keep the PHP classes' structure of your entities as close as possible of the structure exposed through the API.
Your classes should reflect the output of the API. You can use custom data providers to deal with more complex data structure (ex: ORM entities) before hydrating the structure to expose.

Firebase REST API get all data from node as JSON Array

Is there any possibility in Firebase to get data from node as JSON array, but not like multiple objects
For example I have:
https://additive-food-e2a9a.firebaseio.com/additive.json
{"-KjrTAOehl0RAvKYlYVp":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrUIm-itn8h8EjckNQ":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrXlvuJjMuogCJmGDK":{"alias":"Curcumin","danger":"2","name":"E100"}}
But I need something like:
[{"-KjrTAOehl0RAvKYlYVp":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrUIm-itn8h8EjckNQ":{"alias":"Curcumin","danger":"2","name":"E100"},"-KjrXlvuJjMuogCJmGDK":{"alias":"Curcumin","danger":"2","name":"E100"}]
Firebase returns only JSON object when you hit GET request to the node. You have to apply JSON parsing logic in Java, Javascript or whatever language you use.
Sample JSON Parsing logic in Java.

creating C# code to get the value from json file

I have developed one online bus seat booking project, here I am using the API for each operation.
One operation had to write the information in .xml file now which they have changed to .json. Already I have got the value from .xml, but I didn't know how to get the value from .json.
It depends upon type of method you are using. As far as they are GET you can get value from Request.QueryString["Key"] and if the method type is of POST then you can get those from Request.Form["key"].
To return the result in Json format you can either use .Net 3.0 System.Web.script.Serialization namespace which contains Class for converting object to json data JavaScriptSerializer or you can use some third party dll such as JSON.NET One that fall in my favorite list while dealing with jSon data.

Resources