Skip to content

Instantly share code, notes, and snippets.

@zit0un
Last active Jul 24, 2021
Embed
What would you like to do?
OpenAPI (OAS3) definition for GeoJSON objects
openapi: 3.0.0
info:
version: 1.0.0
title: GeoJSON format
description: >
This document defines the GeoJSON format as an OpenAPI.
It contains the definitions for 'Feature' object and 'FeatureCollection'
objects, as well as the definitions for all 'Geometry' objects.
It conforms with the 'RFC-7946' standard from IETF (August 2016 version)
Kudos to @bubbobne and @idkw whose code helped me not start from scratch
https://gist.github.com/bubbobne/fe5f2db65acf039be6a9fd92fc9c7233
termsOfService: 'no'
contact:
name: Zitoun
email: 'zitoun@gmail.com'
license:
name: GPLv3
url: 'https://www.gnu.org/licenses/gpl-3.0.html'
#•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
externalDocs:
description: Official GeoJSON specification – 'IETF RFC-7946' (August 2016)
url: 'https://tools.ietf.org/html/rfc7946'
#•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
security:
- UserSecurity: []
#•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
servers:
- url: 'http://myHost/'
#•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
paths:
#=============================================================================
'/geometry':
get:
summary: Get an array of GeoJSON Geometry objects
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/GeometryCollection'
'400':
$ref: '#/components/responses/BadRequest400ErrorResponse'
'401':
$ref: '#/components/responses/Unauthorized401ErrorResponse'
'500':
$ref: '#/components/responses/Server500ErrorResponse'
post:
summary: Create new GeoJSON Geometry object
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Geometry'
required: true
responses:
'201':
description: New GeoJSON Geometry object created
'400':
$ref: '#/components/responses/BadRequest400ErrorResponse'
'401':
$ref: '#/components/responses/Unauthorized401ErrorResponse'
'403':
$ref: '#/components/responses/Forbidden403ErrorResponse'
'500':
$ref: '#/components/responses/Server500ErrorResponse'
#•••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
components:
#=============================================================================
responses:
'BadRequest400ErrorResponse':
description: The JSON is not valid
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/BasicError'
- type: object
properties:
'type':
type: integer
enum: [400]
'Unauthorized401ErrorResponse':
description: The request requires the user an authentification
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/BasicError'
- type: object
properties:
'type':
type: integer
enum: [401]
'Forbidden403ErrorResponse':
description: The access is not allowed
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/BasicError'
- type: object
properties:
'type':
type: integer
enum: [403]
'NotFound404ErrorResponse':
description: The resource was not found
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/BasicError'
- type: object
properties:
'type':
type: integer
enum: [403]
'Server500ErrorResponse':
description: An unexpected error occured.
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/BasicError'
- type: object
properties:
'type':
type: integer
enum: [500]
#=============================================================================
securitySchemes:
'UserSecurity':
type: http
scheme: basic
#=============================================================================
schemas:
#---------------------------------------------------------------------------
'BasicError':
required:
- code
- message
properties:
'code':
type: integer
minimum: 100
maximum: 600
'message':
type: string
#---------------------------------------------------------------------------
'GeoJsonObject':
description: >
GeoJSon object
The coordinate reference system for all GeoJSON coordinates is a
geographic coordinate reference system, using the World Geodetic System
1984 (WGS 84) datum, with longitude and latitude units of decimal
degrees.
This is equivalent to the coordinate reference system identified by the
Open Geospatial Consortium (OGC) URN
An OPTIONAL third-position element SHALL be the height in meters above
or below the WGS 84 reference ellipsoid.
In the absence of elevation values, applications sensitive to height or
depth SHOULD interpret positions as being at local ground or sea level.
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3'
type: object
properties:
'type':
type: string
enum:
- Feature
- FeatureCollection
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection
'bbox':
type: array
items:
type: number
required:
- type
discriminator:
propertyName: type
#---------------------------------------------------------------------------
'Geometry':
description: >
Abstract type for all GeoJSon object except Feature and
FeatureCollection
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3'
allOf:
- $ref: '#/components/schemas/GeoJsonObject'
- type: object
properties:
'type':
type: string
enum:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
- GeometryCollection
required:
- type
discriminator:
propertyName: type
#---------------------------------------------------------------------------
'GeometryElement':
description: >
Abstract type for all GeoJSon 'Geometry' object the type of which is not
'GeometryCollection'
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3'
allOf:
- $ref: '#/components/schemas/Geometry'
- type: object
properties:
'type':
type: string
enum:
- Point
- MultiPoint
- LineString
- MultiLineString
- Polygon
- MultiPolygon
required:
- type
discriminator:
propertyName: type
#---------------------------------------------------------------------------
'Feature':
description: GeoJSon 'Feature' object
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.2'
allOf:
- $ref: '#/components/schemas/GeoJsonObject'
- type: object
required:
- geometry
- properties
properties:
'geometry':
allOf:
- nullable: true
- $ref: '#/components/schemas/Geometry'
'properties':
type: object
nullable: true
'id':
oneOf:
- type: number
- type: string
#---------------------------------------------------------------------------
'FeatureCollection':
description: GeoJSon 'FeatureCollection' object
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.3'
allOf:
- $ref: '#/components/schemas/GeoJsonObject'
- type: object
required:
- features
properties:
'features':
type: array
items:
$ref: '#/components/schemas/Feature'
#---------------------------------------------------------------------------
'Position':
description: >
GeoJSon fundamental geometry construct.
A position is an array of numbers. There MUST be two or more elements.
The first two elements are longitude and latitude, or easting and
northing, precisely in that order and using decimal numbers.
Altitude or elevation MAY be included as an optional third element.
Implementations SHOULD NOT extend positions beyond three elements
because the semantics of extra elements are unspecified and ambiguous.
Historically, some implementations have used a fourth element to carry
a linear referencing measure (sometimes denoted as "M") or a numerical
timestamp, but in most situations a parser will not be able to properly
interpret these values. The interpretation and meaning of additional
elements is beyond the scope of this specification, and additional
elements MAY be ignored by parsers.
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.1'
type: array
minItems: 2
maxItems: 3
items:
type: number
#---------------------------------------------------------------------------
'LineStringCoordinates':
description: >
GeoJSon fundamental geometry construct, array of two or more positions.
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.4'
type: array
items:
$ref: '#/components/schemas/Position'
minItems: 2
#---------------------------------------------------------------------------
'LinearRing':
description: >
A linear ring is a closed LineString with four or more positions.
The first and last positions are equivalent, and they MUST contain
identical values; their representation SHOULD also be identical.
A linear ring is the boundary of a surface or the boundary of a hole in
a surface.
A linear ring MUST follow the right-hand rule with respect to the area
it bounds, i.e., exterior rings are counterclockwise, and holes are
clockwise.
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.6'
type: array
items:
$ref: '#/components/schemas/Position'
minItems: 4
#---------------------------------------------------------------------------
'Point':
description: GeoJSon geometry
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.2'
allOf:
- $ref: '#/components/schemas/GeometryElement'
- type: object
required:
- coordinates
properties:
'coordinates':
$ref: '#/components/schemas/Position'
#---------------------------------------------------------------------------
'MultiPoint':
description: GeoJSon geometry
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.3'
allOf:
- $ref: '#/components/schemas/GeometryElement'
- type: object
required:
- coordinates
properties:
'coordinates':
type: array
items:
$ref: '#/components/schemas/Position'
#---------------------------------------------------------------------------
'LineString':
description: GeoJSon geometry
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.4'
allOf:
- $ref: '#/components/schemas/GeometryElement'
- type: object
required:
- coordinates
properties:
'coordinates':
$ref: '#/components/schemas/LineStringCoordinates'
#---------------------------------------------------------------------------
'MultiLineString':
description: GeoJSon geometry
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.5'
allOf:
- $ref: '#/components/schemas/GeometryElement'
- type: object
required:
- coordinates
properties:
'coordinates':
type: array
items:
$ref: '#/components/schemas/LineStringCoordinates'
#---------------------------------------------------------------------------
'Polygon':
description: GeoJSon geometry
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.6'
allOf:
- $ref: '#/components/schemas/GeometryElement'
- type: object
required:
- coordinates
properties:
'coordinates':
type: array
items:
$ref: '#/components/schemas/LinearRing'
#---------------------------------------------------------------------------
'MultiPolygon':
description: GeoJSon geometry
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.7'
allOf:
- $ref: '#/components/schemas/GeometryElement'
- type: object
required:
- coordinates
properties:
'coordinates':
type: array
items:
type: array
items:
$ref: '#/components/schemas/LinearRing'
#---------------------------------------------------------------------------
'GeometryCollection':
type: object
description: >
GeoJSon geometry collection
GeometryCollections composed of a single part or a number of parts of a
single type SHOULD be avoided when that single part or a single object
of multipart type (MultiPoint, MultiLineString, or MultiPolygon) could
be used instead.
externalDocs:
url: 'https://tools.ietf.org/html/rfc7946#section-3.1.8'
allOf:
- $ref: '#/components/schemas/Geometry'
- type: object
required:
- geometries
properties:
'geometries':
type: array
items:
$ref: '#/components/schemas/GeometryElement'
minItems: 0
#•••••••••••••••••••••••••••••••••••[ EOF ]••••••••••••••••••••••••••••••••••••#
@nside

This comment has been minimized.

Copy link

@nside nside commented Jul 24, 2021

nice thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment