schema-generator | PHP Model Scaffolding from Schema.org and other RDF | JSON Processing library
kandi X-RAY | schema-generator Summary
kandi X-RAY | schema-generator Summary
schema is a command line tool part of the API Platform framework that instantly generates a set of PHP classes from vocabularies such as (but not limited to) Schema.org or ActivityStreams.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Execute the graph .
- Generate ID attributes .
- Generate class attributes .
- Validate class operations .
- Generate attributes for a property .
- Resolve name .
- Configure the dump configuration .
- Get relation name .
- Generate uses .
schema-generator Key Features
schema-generator Examples and Code Snippets
Community Discussions
Trending Discussions on schema-generator
QUESTION
In my project I have some DTO classes that I use in my REST communication. With Karate I want to create some external e2e/integration tests where I check if the API responses comply with the contract defined in the DTOs. To keep the whole setup DRY I want to avoid manually writing Karate JSON schemas describing the DTOs. Instead I am looking for a way to translate my Java classes into Karate JSON schemas.
What I already have:Let's say this is one of my Java DTOs.
...ANSWER
Answered 2021-May-24 at 17:39I very strongly recommend that you do NOT re-use your production DTO-s for your tests. Think about it, you are setting yourself up for failure - and run the risk of not realizing when a "refactoring" that someone applied via the IDE etc. breaks your API clients.
You should be testing from the perspective of clients which for many teams is a web-browser. That is why Karate avoids Java and sticks to JSON + HTTP.
Second, testing for schema-fit has very little value in my honest opinion. Based on what you said, it is quite likely that your JSON is being generated from the DTO-s already, which makes it even less valuable in your specific case.
Sorry if that sounds harsh, but I see this mistake made all over the place. Being DRY is over-rated especially in a test-automation context.
That said, if you are lucky, the karate.toJson()
method would be able to convert your DTO-s into JSON, but if you are using some fancy annotations it may not work, it is all based on the JavaBean conventions.
Finally I would say just use Java inter-op, call some Java library to do schema validation and call it a day as seen in schema.feature
over here.
To summarize, I think you should forget about schema validation and focus on testing the "business flows" of your API-s, where you typically chain API-s. Create product. Create order. Check if inventory is reduced. Etc etc. Once you have those in place, then think about whether it is worth testing for schema-fit or not.
QUESTION
I wish to use API-Platform to perform CRUD operations on object hierarchy classes. I found little written when using inherited classes with API-Platform and some but not much more when used with Symfony's serializer, and am looking for better direction on what needs to be implemented differently specifically for inherited classes.
Let's say I have Dog, Cat, and Mouse inherited from Animal where Animal is abstract (see below). These entities have been created using bin/console make:entity
, and have only been modified to extend the parent class (as well as their respective repositories) and to have Api-Platform annotation added.
How should groups be used with inherited classes? Should each of the child classes (i.e. Dog, Cat, Mouse) have their own group or should just the parent animal
group be used? When using the animal
group for all, some routes respond with The total number of joined relations has exceeded the specified maximum. ...
, and when mixed, sometimes get Association name expected, 'miceEaten' is not an association.
. Will these groups also allow ApiPropertys on the parent apply to the child entities (i.e. Animal::weight has a default openapi_context example value of 1000)?
API-Platform does not discuss CTI or STI and the only relevant reference I found in the documentation was regarding MappedSuperclass. Need a MappedSuperclass be used in addition to CLI or STI? Note that I tried applying MappedSuperclass
to Animal
, but received an error as expected.
Based on this post as well as others, it appears that the preferred RESTful implementation is to use a single endpoint /animals
instead of individual /dogs
, /cats
, and /mice
. Agree? How could this be implemented with API-Platform? If the @ApiResource()
annotation is applied only to Animal, I get this single desired URL but don't get the child properties for Dog, Cat, and Mouse in the OpenAPI Swagger documentation nor the actual request. If the @ApiResource()
annotation is applied only to Dog, Cat, and Mouse, then there is no way to get a combined collection of all animals and I have multiple endpoints. Need it be applied to all three? It appears that OpenApi's key words oneOf
, allOf
, and anyOf
might provide a solution as described by this stackoverflow answer as well as this Open-Api specification. Does Api-Platform support this and if so how?
Animal
...ANSWER
Answered 2021-Mar-30 at 12:05I don't think a reputable source is available on this subject but i do have long experience with frameworks, abstract user interfaces and php and created MetaClass Tutorial Api Platform so i will try to answer your question myself.
The tutorial aims to cover the common ground of most CRUD and Search apps for both an api platform api and a react client generated with the api platform client generator. The tutorial does not cover inheritance and polymorphism because i do not think it occurs in many CRUD and Search apps but it adresses many aspects that do, for an overview see the list of chapters in the readme of the master branch. Api Platform offers a lot of generic functionality for the api of such apps out of the box that only needs to be configured for specific resources and operations. In the react branches this led to recurring patterns and refactoring into common components and eventually to an extended react client generator to accompany the tutorial. The scheme of serialization groups in this answer is a bit more generic because my understanding of the subject has improved over time.
Your classes worked out of the box on Api Platform 2.6 except for the repository classes that where not included. I removed them from the annotation as right now none of their specific methods seem to be called. You can allways add them again when your need them.
Against the common preference for REST in general to use a single endpoint /animals i chose for individual ones for /dogs, /cats, and /mice because:
- Api Platform identifies instances of resource classes by iri's that refer to these specific endpoints and inludes them as values of @id whenever these instances are serialized. The client generater, and i suppose the admin client too, depend on these endpoints to work for crud operations,
- With Api Platform specific post operations work out of the box with doctrine orm. An endpoint /animals would require a custom Denormalizer that can decide which concrete class to instantiate.
- With serialization groups specific end points give more control over serializations. Without that is it hard to get serialization compatible with the way it is done in chapter 4 of the tutorial,
- In many of the extension points of Api Platform it is easy to make things work for a spefic resource and all examples in the docs make use of that. Making them specific for the actual concrete subclass of the object at hand is undocumented and may not allways be possible.
I only include the /animals get collection operation because that allows the client to retrieve, search and sort a polymophic collection of animals in a single request.
In line with chapter 4 of the tutorial i removed the write annotation groups. Api Platforms deserialization already allows the client to only include those properties with post, put and patch that hold data and are meant be set, so the only purpose of deserialization groups can be to disallow certain properties to be set through (certain operations of) the api or to allow the creation of related objects through nested documents. When i tried to add a new cat by posting it as value of $ateByCat of a mouse i got error "Nested documents for attribute "ateByCat" are not allowed. Use IRIs instead." The same happened with adding one through Dog::$catsChased, so security by operation with certain roles granted does not seem to be compromised without write annotation groups. Seems like a sound default to me.
I added a ::getLabel method to Animal to represent each by a single string (annotated as http://schema.org/name). Basic CRUD and Search clients primarily show a single type of entities to the user and represent related entities this way. Having a specific schema.org/name property is more convenient for the client and making it a derived property is more flexible then then adding different properties depending on the type of entity. The label property is the only property that is added to the "related" group. This group is added to the normalization context of each type so that for the "get" operations of Cat, Doc and Mouse it is the only property serialized for related objects:
QUESTION
I am creating a Apollo Graphql backend using type-orm. I create an entity called Project:
...ANSWER
Answered 2021-Mar-14 at 20:44I have managed to solve the problem by changing the import of the class 'Project' made in the 'ProjectResolver' class.
Instead of:
import {Project} from '../entities/project'
Now looks like this:
import {Project} from '../../src/entities/project'
QUESTION
I have a project where I have updated all of the packages.
Before the update all e2e tests functioned as expected.
After the update, The product itself compiles and runs as expected.
However, the e2e tests are showing unexpected issues both in the IDE and at run time.
For example,
...ANSWER
Answered 2021-Jan-21 at 19:52Finally figured out a solution after visiting the NPM page for axe-cypress.
QUESTION
I'm using jsonschema-generator to generate a JSON schema file based on my POJOs. Currently I'm doing it via a test that is run during the gradle build
step. This works fine but it doesn't feel right as really what I'm doing is not testing anything.
I've also found this answer which details how to run it on gradle run
but this is not ideal either as it will pointlessly execute this every time the application comes up but not when I build.
Therefore, is there a way to tell gradle (in build.gradle
) to run a piece of Java code at build time?
For completeness, here the code I'm looking to run:
...ANSWER
Answered 2020-Apr-05 at 19:03The JavaExec Plugin seems to meet your requirements.
This allows you to run a main()
method and thereby any Java Code you want – including whatever JSON Schema generation you like.
This other answer also describes pretty much what you want to do.
Adapted from the linked documentation:
QUESTION
I am experimenting with NestJS
and TypeGraphQL
. And I have an example model of a cat.
ANSWER
Answered 2020-Feb-23 at 09:24TypeGraphQL by default doesn't inherit all @Field
s from parent classes that are not decorated with @InputType
or @ObjectType
because this types should not be mixed as things like unions and interfaces are invalid GraphQL input types.
So if you are sure you're not violating this rules, just place both decorators on top of the class:
QUESTION
I'm in struggle since few days with e2e testing my NestJS application using GraphQL code first approach and TypeOrm.
I'm trying to create a TestingModule by injecting nestjs GraphQLModule with autoSchemaFile and I'm always getting the error "Schema must contain uniquely named types but contains multiple types named ...".
Here a reproduction of my bug with minimal code:
character.entity.ts
:
ANSWER
Answered 2020-Feb-19 at 08:46Your ormconfig.json
need to look like this:
QUESTION
I got a JSON-File, that contains a various number of addresses. Now I need a JSON-Schema to validate the complete JSON-File:
My JSON-File is looking similar to this:
...ANSWER
Answered 2019-Nov-18 at 13:14You can use NJsonSchema Library (accessible via Nuget Packages) for generating schema from Json directly. For example,
QUESTION
I would like to create a Custom Extension in my API, created thanks to api-platform. I tried to follow the documentation about extensions to do exactly the same thing : get data owned by the current user. But I've the following error :
(1/1) FatalThrowableError Type error: Argument 1 passed to AppBundle\Doctrine\ORM\Extension\CurrentUserExtension::__construct() must implement interface Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface, none given, called in /var/www/api/var/cache/dev/appDevDebugProjectContainer.php on line 579
I tried to remove cache files, but I've the same issue.
My configuration :
symfony/symfony v3.3.10
api-platform/schema-generator : v1.2.0
api_filters.yml :
...ANSWER
Answered 2017-Oct-23 at 17:09problem solved :
service.yml :
QUESTION
Regexes seem to be accepted schemas:
...ANSWER
Answered 2017-Apr-28 at 08:11If we use the miner/strgen
library we can indeed work up a solution:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install schema-generator
PHP requires the Visual C runtime (CRT). The Microsoft Visual C++ Redistributable for Visual Studio 2019 is suitable for all these PHP versions, see visualstudio.microsoft.com. You MUST download the x86 CRT for PHP x86 builds and the x64 CRT for PHP x64 builds. The CRT installer supports the /quiet and /norestart command-line switches, so you can also script it.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page