-
-
Save codan-telcikt/e1d59ccc9a3af83e083f1a514c84026c to your computer and use it in GitHub Desktop.
An OpenAPI definition for GeoJSON with Geometry and Features.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# MIT License | |
# | |
# Copyright (c) 2017 Daniele Andreis <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
swagger: '2.0' | |
info: | |
version: "1.0.0" | |
title: GeoJSON geometry | |
description: An example of an OpenAPI definition for GeoJSON with Geometry and Features. | |
termsOfService: "no" | |
contact: | |
name: Tim Telcik | |
email: [email protected] | |
url: "" | |
license: | |
name: GPLv3 | |
url: https://www.gnu.org/licenses/gpl-3.0.html | |
externalDocs: | |
description: RFC7946 - The GeoJSON format. | |
url: https://tools.ietf.org/html/rfc7946 | |
schemes: | |
- http | |
host: myHost | |
basePath: /v1 | |
consumes: | |
- "application/json" | |
produces: | |
- "application/json" | |
securityDefinitions: | |
UserSecurity: | |
type: basic | |
# AdminSecurity: | |
# type: basic | |
# MediaSecurity: | |
# type: basic | |
#globalmente e' userSecurity ma posso cambiare localmente | |
security: | |
- UserSecurity: [] | |
paths: | |
/geometries: | |
get: | |
summary: GeoJSON geometry array | |
responses: | |
200: | |
description: Successful response | |
schema: | |
type: array | |
items: | |
$ref: "#/definitions/GeometryCollection" | |
400: | |
$ref: "#/responses/BadRequest400ErrorResponse" | |
401: | |
$ref: "#/responses/Unauthorized401ErrorResponse" | |
500: | |
$ref: "#/responses/Standard500ErrorResponse" | |
post: | |
summary: Create new geometry | |
parameters: | |
- name: geom | |
in: body | |
required: true | |
schema: | |
$ref: "#/definitions/Geometry" | |
responses: | |
201: | |
description: new geometry created | |
400: | |
$ref: "#/responses/BadRequest400ErrorResponse" | |
401: | |
$ref: "#/responses/Unauthorized401ErrorResponse" | |
403: | |
$ref: "#/responses/Forbidden403ErrorResponse" | |
500: | |
$ref: "#/responses/Standard500ErrorResponse" | |
definitions: | |
Error: | |
required: | |
- code | |
- message | |
properties: | |
code: | |
type: string | |
message: | |
type: string | |
Geometry: | |
type: object | |
description: GeoJSon geometry | |
discriminator: type | |
required: | |
- type | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#geometry-objects | |
properties: | |
type: | |
type: string | |
enum: | |
- Point | |
- LineString | |
- Polygon | |
- MultiPoint | |
- MultiLineString | |
- MultiPolygon | |
description: the geometry type | |
Point3D: | |
type: array | |
description: Point in 3D space | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id2 | |
minItems: 2 | |
maxItems: 3 | |
items: | |
type: number | |
Point: | |
type: object | |
description: GeoJSon geometry | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id2 | |
allOf: | |
- $ref: "#/definitions/Geometry" | |
- properties: | |
coordinates: | |
$ref: '#/definitions/Point3D' | |
LineString: | |
type: object | |
description: GeoJSon geometry | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id3 | |
allOf: | |
- $ref: "#/definitions/Geometry" | |
- properties: | |
coordinates: | |
type: array | |
items: | |
$ref: '#/definitions/Point3D' | |
Polygon: | |
type: object | |
description: GeoJSon geometry | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id4 | |
allOf: | |
- $ref: "#/definitions/Geometry" | |
- properties: | |
coordinates: | |
type: array | |
items: | |
type: array | |
items: | |
$ref: '#/definitions/Point3D' | |
MultiPoint: | |
type: object | |
description: GeoJSon geometry | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id5 | |
allOf: | |
- $ref: "#/definitions/Geometry" | |
- properties: | |
coordinates: | |
type: array | |
items: | |
$ref: '#/definitions/Point3D' | |
MultiLineString: | |
type: object | |
description: GeoJSon geometry | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id6 | |
allOf: | |
- $ref: "#/definitions/Geometry" | |
- properties: | |
coordinates: | |
type: array | |
items: | |
type: array | |
items: | |
$ref: '#/definitions/Point3D' | |
MultiPolygon: | |
type: object | |
description: GeoJSon geometry | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#id6 | |
allOf: | |
- $ref: "#/definitions/Geometry" | |
- properties: | |
coordinates: | |
type: array | |
items: | |
type: array | |
items: | |
type: array | |
items: | |
$ref: '#/definitions/Point3D' | |
GeometryCollection: | |
type: object | |
description: GeoJSon geometry collection | |
required: | |
- type | |
- geometries | |
externalDocs: | |
url: http://geojson.org/geojson-spec.html#geometrycollection | |
properties: | |
type: | |
type: string | |
enum: | |
- GeometryCollection | |
geometries: | |
type: array | |
items: | |
$ref: '#/definitions/Geometry' | |
Feature: | |
type: object | |
description: GeoJSon Feature | |
required: | |
- type | |
- id | |
- geometry | |
externalDocs: | |
url: https://tools.ietf.org/html/rfc7946#section-3.2 | |
properties: | |
type: | |
type: string | |
enum: | |
- Feature | |
id: | |
type: integer | |
geometry: | |
$ref: '#/definitions/GeometryCollection' | |
properties: | |
type: object | |
FeatureCollection: | |
type: object | |
description: GeoJSon Feature collection | |
required: | |
- type | |
- features | |
externalDocs: | |
url: https://tools.ietf.org/html/rfc7946#section-3.3 | |
properties: | |
type: | |
type: string | |
enum: | |
- FeatureCollection | |
features: | |
type: array | |
items: | |
$ref: '#/definitions/Feature' | |
responses: | |
Standard500ErrorResponse: | |
description: An unexpected error occured. | |
schema: | |
$ref: "#/definitions/Error" | |
BadRequest400ErrorResponse: | |
description: The JSON is not valid | |
schema: | |
$ref: "#/definitions/Error" | |
Unauthorized401ErrorResponse: | |
description: The request requires an user authentication | |
schema: | |
$ref: "#/definitions/Error" | |
Forbidden403ErrorResponse: | |
description: the access is not allowed | |
schema: | |
$ref: "#/definitions/Error" | |
# NotFound404ErrorResponse: | |
# description: not found check the path or the query | |
# schema: | |
# $ref: "#/definitions/Error" | |
# Ok200Response: | |
# description: Eyerything is working | |
# schema: | |
# $ref: "#/definitions/OK" | |
# Create201Response: | |
# description: New resource has been created | |
# schema: | |
# $ref: "#/definitions/OK" | |
# Delete204Response: | |
# description: The resource was successfully deleted | |
# schema: | |
# $ref: "#/definitions/OK" |
Thank you for sharing, this was really helpful for me!
A couple of suggestions:
Geometry
>properties
>type
>enum
is missing the optionGeometryCollection
(listed in https://datatracker.ietf.org/doc/html/rfc7946#section-1.4)- The
id
property ofFeature
is optional (see https://datatracker.ietf.org/doc/html/rfc7946#section-3.2) so it should not be inFeature
>required
- The
id
property ofFeature
can be a string or a number (see https://datatracker.ietf.org/doc/html/rfc7946#section-3.2) soFeature
>properties
>id
should beanyOf
type: string
ortype: integer
- Any GeoJSON object may optionally have a
bbox
property (see https://datatracker.ietf.org/doc/html/rfc7946#section-5) with a schema similar to:BoundingBox: type: array externalDocs: url: https://tools.ietf.org/html/rfc7946#section-5 minItems: 4 maxItems: 6 items: type: number
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good