Ask a Question

validate OpenAPI Specification Document

venkireddy1991
Occasional Contributor

validate OpenAPI Specification Document

Hi Team,

 

I got the Open API Specificatipon (.yaml) file from my de team,I would like to validate the Definition file against certain guide lines/styles/ruleset....

 

Could you please let me know how can do this with ready API Tool..

 

Note : I am able to verify this with other like like,Linters(Spectral,oval etc)....

 

Please suggest as soon as possible.

 

Thank you very much....

 

10 REPLIES 10
nmrao
Community Hero

@venkireddy1991 

I would do this. Go to https://editor.swagger.io/

When the yaml file is opened, there should not be any errors.

Have you tried ? Is this what you want?

Automatic way, not sure.

 



Regards,
Rao.
richie
Community Hero

Hi @venkireddy1991

Just to reiterate what Rao has already stated and to add a bit of additional detail.

Using .json and .xml as an example, you get wellformed checks and valid checks.
Wellformed (which checks a file to ensure it corresponds to wellformed syntax rules (which is doneby the parser). Wellformed checks are done by the parser so no additional file is required. Simply put, the file to be checked by the parser is all thats required.
Valid checks (known as schema valid/invalid) check the content of a file conforms to rules defined in ANOTHER file (known as the schema) and these schema valid rules check content, format, datatypes, field lengths, value format/pattern etc. and all these rules are defined in the schema.

Quite often the terminology can be a confused....e.g. a lot of online json validators dont check for validation, they simply check to ensure the file is wellformed.....i.e. to check a file is valid on these online tools, youd have to load up the schema file first and then load of the file you want to ensure is valid and the tool would then compare the and file to ensure it conforms to the rules defined in your schema (the first file loaded in my example).

Your openAPI/swagger .json file is the definition (the schema itself) so you can only check the .yaml files wellformedness.

ReadyAPI! doesn't include a function to check wellformedness independently. The wellformed check is done by whichever ReadyAPI! Parser is executed when a file is loaded into ReadyAPI!
If the file loads with no errors being reported, by definition, the file has been parsed and checked for wellformedness and it has passed the wellformed check. Only if errors were reported (hindering successfully loading in your openAPI file) would the file be malformed.

As i said your file IS the schema so you can only check to ensure its not malformed.

Best case you can check the files youll be submitting against your openAPI .yaml (the schema) to ensure your files are schema valid.

Hope the above has clarified a bit,

Nice one,

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
venkireddy1991
Occasional Contributor

Thank you for all your responses.

 

Wellformed checks (something like valid document format etx)can be done when you load the Spec file in the tools.(Ready API etc...)

 

Let us consider the beow Checks

1. Contact details shpuld have emai and phone number

2.should contains title and descriptions

3.Servers shoud not contain "\" at the end

4.Methods should be snake_case.....

 

etc..some thing like this....Before Dev team develops the APIs,as part of Testing team you need to ensure that they follow these guide lines while desining  the Spec files...

 

I can actually use SwaggerCompliance assertion to veryfy the Responses are appropriate as per the Spec file...but this is after the Actual API Development is done...

 

Just looking for some thing in ready API to check the Spec files.(Something similar to the Spectral CLI or OVAL or  Speccy)

 

Anyways I dont see I can do this with Ready API.....I will can continue doing with spectral and ensure the Spac file is true..

 

Our goal is to ensure the Spc file is single source of truth for Dev,QA or any other teams...

 

 

Hi @venkireddy1991 ,

I appreciate this doesnt help with your problem...as you already state ReadyAPI! performs a wellformed check when you load in a file and each time the file is parsed, but i just wanted to mention the detail below as this might steer you in another direction.

The checks you mention in your last appear to a mix of what id consider as 'validation' along with a single 'wellformed' check.

I appreciate you want to ensure the developers code adheres to the rules defined in your openAPI .yaml, but whether this is actually necessary or not depends on how the developers are creating the apis themselves.

What i mean by this is there are tools out there that support the creation and update of the openAPI (.yaml) files. What i mean is there are tools such as Smartbears Swagger that allow the user to create your .yaml file and this .yaml file is then used by developers to create the code for the apis themselves (at least i think this is the way it works), so the .yaml is a framework and the apis defined in the .yaml can be generated dynamically from the .yaml. if this is the case (and i think it is from the reading i've just done) then checking the developed apis conform to the rules in the .yaml is moot because the .yaml was used to generate the apis themselves.

I hope ive been clear

Cheers

Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
venkireddy1991
Occasional Contributor

Team,

 

How can add swagger compliance assertion using script??

 

 

@venkireddy1991 :

 

Hope below link will help you to add assertion

 

assertions-compliance-swagger 

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal

Thanks for your reply....

 

But Would like to know how to add in Script..using groovy Script...

The 4 points which are mentioned are very specific to your use case. This is actually something you want to have checks on metadata.

So I believe that one can write an utility to parse the yaml and have the desired checks.


Regards,
Rao.

Are you creating the ReadyAPI project automatically? Or using the tool? If project is crated using the tool then it is rather simple to create the desired assertion by hand as it is one time job.

Creating automatic assertion would make sense when project itself is created automatically.

What's your case?


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: