godtaehee / Swagger

0 stars 0 forks source link

Open API Specification Basics #4

Open godtaehee opened 3 years ago

godtaehee commented 3 years ago

Start

You first start with a swagger key and its value is always 2.00 in quotes.

This is because before it became the Open API Specification, the specification was called Swagger 2.0 스크린샷 2021-08-05 오후 12 16 04

Request

Request will have the URL end point, the HTTP method, path parameters, query parameters, request body, responses.

스크린샷 2021-08-05 오후 12 22 48

paths

First there is paths key which will have a list of paths.

In other words different operations grouped by URL.

YAML has a dash which inidicates a list. That's because we have a list of parameters.

The query parameter has a name key which in this case has a start value and it has an in key which has a value of query, which means that it's a query parameter.

The required key is set to false in this case, indicating that the start parameter is optional, and the type key is set to the string.

스크린샷 2021-08-05 오후 12 34 08

This URL ends in /album/integer where the integer is the album ID.

So if we look at the definition in the paths key is now /album/ID where ID is in curly brackets.

This indicates that there will be a path parameter defined later with a name of ID.

Again we have a method of get in the parameters list. This time we have just one parameter, which, as I mentioned before, has a name of id.

The in value is path, which means that it's a path parameter and that's part of URL.

In this case, required is true and that's almost always the case for path parameters. And the type is integer.

the type key can have serveral values.

These include:

Custom headers

If your request has custom headers, they are also treated as parameters.

스크린샷 2021-08-05 오후 12 42 50

In this example, you have this YAML code in the parameters list for a header named Access-level.

The in value is set to header, meaning that it's the header; the required value is false, meaning that it's optional; and the type is string.

Swagger Editor

The Swagger web site provides an editor for Open API Specification files. Go to editor2.swagger.io

It creates color-coded YAML on the left side on the right side it shows you what the documentation will look like once you create it.