Skip to content

Instantly share code, notes, and snippets.

@bubbobne
Last active November 2, 2023 19:08
Show Gist options
  • Save bubbobne/fe5f2db65acf039be6a9fd92fc9c7233 to your computer and use it in GitHub Desktop.
Save bubbobne/fe5f2db65acf039be6a9fd92fc9c7233 to your computer and use it in GitHub Desktop.
A #swagger #geojson geometry description
#MIT License
#
#Copyright (c) 2017 Daniele Andreis
#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 swagger file for a geographic API. It contains the geometry definitions
termsOfService: "no"
contact:
name: Daniele Andreis
email: [email protected]
url: ""
license:
name: MIT
url: https://opensource.org/licenses/mit-license.php
externalDocs:
description: find more info here
url: http://geojson.org/geojson-spec.html#geometry-objects
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
description:
responses:
200:
description: Successful response
schema:
type: array
items:
$ref: "#/definitions/Geometry<Collection"
400:
$ref: "#/responses/BadRequest400ErrorResponse"
401:
$ref: "#/responses/Unauthorized401ErrorResponse"
500:
$ref: "#/responses/Standard500ErrorResponse"
post:
summary: Create new geometry
description:
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
Point2D:
type: array
maxItems: 2
minItems: 2
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/Point2D'
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/Point2D'
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/Point2D'
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/Point2D'
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/Point2D'
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/Point2D'
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
description:
geometries:
type: array
items:
$ref: '#/definitions/Geometry'
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"
@idkw
Copy link

idkw commented Dec 21, 2016

Thanks for writing this spec, it saves me a lot of time !
I've found some formatting issues, making the spec invalid with swagger-editor.
I've fixed them, here it is : https://gist.github.com/idkw/fc35bb78c4bf08e47708f57b060996fe

@dostolu
Copy link

dostolu commented Jun 9, 2018

Point2d d is suppose to be capital as you refer it it with capital

@bubbobne
Copy link
Author

Thanks @dostolu, I have fixed it,

@zit0un
Copy link

zit0un commented Dec 1, 2020

Here is an OpenAPI 3 definition of the RFC-7946 GeoJSON objects specification:
https://gist.github.com/zit0un/3ac0575eb0f3aabdc645c3faad47ab4a
It includes Features and FeatureCollection as well as inheritance between the different objects.
You might want to check it and update your file if you need.

Thank you for helping me not start from scratch ;)

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