Skip to main content

Swagger (OpenAPI) 2.0

A Swagger (OpenAPI) 2.0 definition can be converted to or from an FSD file using the fsdgenswagger command-line tool.

fsdgenswagger

fsdgenswagger is a command-line tool that converts Swagger to FSD or FSD to Swagger.

Install fsdgenswagger as documented from its NuGet package.

fsdgenswagger accepts an FSD file or a Swagger file as input and generates an FSD file or a Swagger file as output. It supports the standard command-line options as well as the following additional command-line options:

  • --fsd: Generates an FSD file (instead of a Swagger file).
  • --json: Generates JSON (instead of YAML) when generating a Swagger file.
  • --service-name <name>: Overrides the service name.

Swagger Schema

This section describes the Swagger fields supported by Facility and their equivalent in FSD.

Not every feature in Swagger is supported. Facility API information without a corresponding Swagger field is stored in an extension field (starts with x-).

Facility does not currently support $ref fields that span files.

Facility supports both JSON and YAML formats for a Swagger definition file.

Swagger Object

Defines the service.

Field NameFSD Equivalent
swagger(always 2.0)
info(see Info Object)
host[http(url: "...://(host)/...")] on service
basePath[http(url: ".../(basePath)")] on service
schemes[http(url: "(scheme)://...")] on service
consumes(ignored)
produces(ignored)
paths(see Path Object)
definitions(see Schema Object)
parameters(see Parameter Object)
responses(see Responses Object)
securityDefinitions(ignored)
security(ignored)
tags(ignored)
externalDocs(ignored)

Only one scheme is supported by FSD. https is preferred over http.

Info Object

Defines the service.

Field NameFSD Equivalent
titleservice summary
descriptionservice remarks
termsOfService(ignored)
contact(ignored)
license(ignored)
version[info(version: (version))] on service
x-identifierservice name
x-codegen(set by fsdgenfsd --swagger)

If the service name is not specified by x-identifier or the --serviceName command-line option, a service name is created from the title.

Path Object

Defines one or more methods.

Field NameFSD Equivalent
(path)[http(path: "(path)")] on method (see Path Item Object)

Path Item Object

Defines one or more methods.

Field NameFSD Equivalent
$ref(supports internal references)
get[http(method: GET)] on method (see Operation Object)
put[http(method: PUT)] on method (see Operation Object)
post[http(method: POST)] on method (see Operation Object)
delete[http(method: DELETE)] on method (see Operation Object)
options[http(method: OPTIONS)] on method (see Operation Object)
head[http(method: HEAD)] on method (see Operation Object)
patch[http(method: PATCH)] on method (see Operation Object)
parameters(see Parameter Object)

Operation Object

Defines a method.

Field NameFSD Equivalent
tags(ignored)
summarymethod summary
descriptionmethod remarks
externalDocs(ignored)
operationIdmethod name
consumes(application/json as appropriate)
produces(application/json as appropriate)
parameters(see Parameter Object)
responses(see Responses Object)
schemes(ignored)
deprecated[obsolete] on method
security(ignored)

If operationId is not specified, a method name is created from the HTTP method and path.

Parameter Object

Defines a request field and its type.

Field NameFSD Equivalent
$ref(supports internal references)
in[http(from: (path|query|header|body))] on field (formData not supported)
namequery, path, or header name
descriptionfield summary
required(true for path parameter; ignored otherwise)
schema(see Schema Object)
typefield type (see Data Types)
formatfield type (see Data Types)
allowEmptyValue(ignored)
itemsarray value type (see Data Types)
collectionFormat(ignored)
default(ignored)
maximum(ignored)
exclusiveMaximum(ignored)
minimum(ignored)
exclusiveMinimum(ignored)
maxLength(ignored)
minLength(ignored)
pattern(ignored)
maxItems(ignored)
minItems(ignored)
uniqueItems(ignored)
enumenum values
multipleOf(ignored)
x-identifierfield name
x-obsolete[obsolete] on field

If x-identifier is not specified, the field name is set to the name field (or "body" for body fields).

Responses Object

Defines response fields of a method.

Field NameFSD Equivalent
(code)[http(code: (code))] on the method or the corresponding body field (see Response Object)

Response Object

Defines response fields of a method.

Field NameFSD Equivalent
$ref(supports internal references)
descriptionbody field summary
schemaresponse field(s) or body field (see Schema Object)
headers(ignored)
examples(ignored)
x-identifierbody field name

If operationId is not specified, a method name is created from the HTTP method and path.

Schema Object

An items object, header object, or schema object. Defines a DTO, a field, or a field type.

Field NameFSD Equivalent
$ref(supports internal references)
descriptionfield summary
required(ignored)
title(ignored)
typefield type (see Data Types)
formatfield type (see Data Types)
itemsarray value type (see Data Types)
maxProperties(ignored)
minProperties(ignored)
default(ignored)
maximum(ignored)
exclusiveMaximum(ignored)
minimum(ignored)
exclusiveMinimum(ignored)
maxLength(ignored)
minLength(ignored)
pattern(ignored)
maxItems(ignored)
minItems(ignored)
uniqueItems(ignored)
enumenum values
multipleOf(ignored)
propertiesDTO fields
allOf(ignored)
additionalPropertiesmap value type (see Data Types)
discriminator(ignored)
readOnly(ignored)
xml(ignored)
externalDocs(ignored)
example(ignored)
x-identifierfield name
x-obsolete[obsolete] on field
x-remarksDTO remarks

If x-identifier is not specified, the field name is set to the name field (or "body" for body fields).

Data Types

The following table describes how each Swagger type and optional format map to an FSD field type.

Swagger typeSwagger formatFSD Type
booleanboolean
integerint32
integerint32int32
integerint64int64
numberdouble
numberfloatdouble
numberdoubledouble
numberdecimaldecimal
stringstring, enum
stringbytebytes
stringbinarystring
stringdatestring
stringdate-timestring
stringpasswordstring
objectDTO, error, result<T>, map<T>, object
arrayT[]
file(not supported)