-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: oas validatie pre commit #75
Conversation
.spectral.yml
Outdated
message: '{{path}} is gedefinieerd als een inline object. Definieer deze als een schema component en verwijs hiernaar met $ref' | ||
type: style | ||
resolved: false | ||
given: '$.components.schemas..properties[?(@.type === "object")]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dit werkt alleen wanneer ook echt type: "object is opgenomen. Dit is default dus kan je ook weglaten.
Als ik dus in common.yaml type: object weghaal wordt geen Warning meer gegeven, bijvoorbeeld bij property first:
HalPaginationLinks:
allOf:
- $ref: "#/components/schemas/HalCollectionLinks"
- type: "object"
properties:
first:
description: "uri voor het opvragen van de eerste pagina van deze collectie"
properties:
href:
type: "string"
example: "/resourcenaam?page=1"
templated:
type: boolean
title:
type: "string"
example: "Eerste pagina"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kan je deze niet beter definiëren met:
given: '$.components.schemas..properties[*].properties'
then:
function: falsy
.spectral.yml
Outdated
type: style | ||
given: '$.components.schemas.*~' | ||
then: | ||
function: pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waarom gebruik je hier niet:
then:
function: casing
functionOptions:
type: pascal
.spectral.yml
Outdated
given: '$.components.parameters[?(@.in == "query")]' | ||
then: | ||
field: name | ||
function: pattern |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waarom gebruik je hier niet:
then:
function: casing
functionOptions:
type: camel
Misschien kan je deze ook toevoegen:
|
En deze ook:
|
👍, ga ik aanpassen |
then: Nice. Mijn oplossing was gewoon een copy paste uit https://github.com/openapi-contrib/style-guides/blob/master/openapi.yml. Ik had niet gezien dat deze als Core Function beschikbaar is. Zal ik aanpassen |
- toevoegen van openapi contact en license info
👍 |
👍 |
@JohanBoer Bij een fout (bijv. weghalen "path: {}") zie ik (in Atom) dat de commit mislukt en krijg ik alle fouten én warnings te zien. Maar bij alleen warnings (iets anders wijzigen zonder fout) gaat de commit door en zie ik de warnings niet. Wanneer ik de commit doe in de CLI zie ik die wel. Hoe doe jij je commits? Kan jij ook testen of jij in jouw werkwijze waarschuwingen te zien krijgt? |
.spectral.yml
Outdated
then: | ||
- field: "properties" | ||
function: truthy | ||
allof-single-extention: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mijn schuld (je hebt dit van mij overgenomen). Typefout extention --> extension
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gefixt
then: | ||
function: casing | ||
functionOptions: | ||
type: pascal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gevolg is dat alle *_links, *_embedded, *_enum en *_tabel componenten een waarschuwing geven. Het opnemen van een underscore is namelijk niet in lijn met UpperCamelCase/PascalCase.
Vanuit consistentie zou ik het ook beter vinden deze underscore weg te halen.
Kan dat nu nog zonder grote consequenties? In BAG en BRK hebben we ook underscore in de schemacomponent namen gebruikt (dan ontstaat er weer inconsistentie tussen de Haal Centraal API's). Of kunnen we die ook aanpassen in de eerstvolgende release? M.a.w. levert dat breaking changes op bij iemand?
Issue #75 hiervoor gemaakt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bij *_links, *_embedded, *_tabel leidt het tot een breaking change bij de providers, niet bij de consumers omdat de consumers niets doen met de classes zelf. Voorwaarde is alleen hernoemen van de schema naam en niet property namen.
Voor de _enums zal ik het testen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_links en _embedded zijn reserved words in hal+json. Als je de underscores weghaalt dan wordt het plain json en moet je het content-type erop aanpassen. Dit is een afweging. Vind je consistentie in de naamgeving van properties belangrijker dan het voldoen aan de draft van json hal. Mijn voorkeur gaat naar het handhaven van de underscores bij _links en _embedded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_links en _embedded zijn reserved words in hal+json. Als je de underscores weghaalt dan wordt het plain json en moet je het content-type erop aanpassen. Dit is een afweging. Vind je consistentie in de naamgeving van properties belangrijker dan het voldoen aan de draft van json hal. Mijn voorkeur gaat naar het handhaven van de underscores bij _links en _embedded.
Even een check. @fsamwel, je hebt hier alleen over de component namen toch? Niet over de properties, want hernoemen van propertynamen leidt tot breaking changes bij zowel consumers als providers.
Ik ben het dus eens met @JohanBoer om _embedded en _links property namen niet te veranderen en ook hal json te blijven als content type.
Ik ga kijken of de jsonpath kan worden aangepast zodat de _links en _embedded properties niet worden meegenomen in de casing check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ja, het gaat hier om de componentnamen, niet om de propertynamen.
Ik denk dat het in de validatie kan worden aangepast door toch niet de built in functie casino (Pascal) te gebruiken, maar zelf een reguliere expressie te maken die deze extensies wel toelaat:
/^([A-Z][a-z0-9]+)+(_embedded|_links|_enum|_tabel)?$/
Ik krijg geen warning te zien in Atom. Blijkbaar constateert die linter de warnings niet. Ik doe mijn commits in Atom via het Git tabje. |
In Visual Studio Code heb ik een output window waar ik de git logs kan zien. Ik moet dan wel de in de output dropdown git selecteren. Misschien heeft Atom ook iets soortgelijks |
Als we tijdens commit warning als error willen zien, dan moet je -F warn toevoegen |
@MelvLee zou je de allof regels nog eens kunnen aanpassen. het blijkt dat allOf op verschillende plekken kan voorkomen. Dus moet de given ook dieper zoeken
Bijvoorbeeld deze werd niet gevonden:
|
👍 |
Ook denk ik een leuke regel:, om te checken dat we niet onnodig gedetailleerd responses definiëren:
|
Gebruik van pre-commit Git Hook om OAS file te valideren voordat wijzigingen worden gecommit.
Pre-requisite: npm. Deze kan worden geïnstalleerd door node.js te installeren.
In de haal-centraal-common map de volgende statements aanroepen:
Bij elke commit wordt nu de
npm run lint
statement automatisch aangeroepen. Bij errors wordt de commit afgebroken.In deze p.r. zitten alleen nog warnings. Om te testen dat bij een commit de common.yaml wordt gevalideerd, kan je de
path: {}
regel uit common.yaml verwijderen en de wijziging committen.Ik heb ervoor gekozen om Spectral als OAS linter te gebruiken omdat het mogelijk is om eigen validatie regels toe te voegen. De validatie regels worden geschreven in yaml. Ook is het makkelijk om validatie regels uit te zetten.
Voorbeeld van een validatie regel:
.spectral.yml is een custom ruleset die de Spectral ruleset extend. Ik heb validaties toegevoegd voor Camelcase, PascalCase en inline object als property