openapi: 3.0.3
info:
  title: Yet another geocoder
  description: |-
    Geocoding and geosuggest service for North-West Russia.
  version: 1.0.0
servers:
  - url: https://geocoder.demostage.ru/api/v1
    description: Public API v1
  - url: https://geocoder.demostage.ru
    description: Legacy alias (deprecated `/?m=` routes)
tags:
  - name: Methods
paths:
  /forward:
    get:
      tags:
        - Methods
      summary: Geocode
      description: |-
        Find coordinates by address. Supports typo-tolerant matching
        (pg_trgm) when full-text search does not match exactly.
      operationId: forward
      parameters:
        - name: q
          in: query
          description: Address
          required: true
          schema:
            type: string
            example: 'Olgina alevik, Narva mnt 8'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildingListResponse'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - api_key: []
  /reverse:
    get:
      tags:
        - Methods
      summary: Reverse geocode
      description: find address by coordinates
      operationId: reverse
      parameters:
        - name: lat
          in: query
          description: latitude
          required: true
          schema:
            type: number
            format: float
            minimum: -90
            maximum: 90
            example: 59.887836403017346
        - name: lng
          in: query
          description: longitude
          required: true
          schema:
            type: number
            format: float
            minimum: -180
            maximum: 180
            example: 30.324198192236167
        - name: radius
          in: query
          description: search radius in meters
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 1000000
            example: 1000
            default: 1000
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildingListResponse'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - api_key: []
  /suggest:
    get:
      tags:
        - Methods
      summary: Suggest
      description: |-
        Geo suggest for address autocomplete. Supports typo-tolerant
        street and building matching when full-text search returns no results.
      operationId: suggest
      parameters:
        - name: s
          in: query
          description: Address
          required: true
          schema:
            type: string
            example: 'Narva'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SuggestResponse'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - api_key: []
  /buildings/{id}:
    get:
      tags:
        - Methods
      summary: Building
      description: Get building by id
      operationId: building
      parameters:
        - name: id
          in: path
          description: Building ID
          required: true
          schema:
            type: string
            example: '12'
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BuildingResponse'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - api_key: []
  /districts:
    get:
      tags:
        - Methods
      summary: Districts
      description: Get districts
      operationId: districts
      parameters:
        - name: l
          in: query
          description: Admin level of districts
          required: false
          schema:
            type: integer
            example: 6
            default: 5
      responses:
        '200':
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DistrictListResponse'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - api_key: []
components:
  responses:
    Forbidden:
      description: Not authorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Page not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UnprocessableEntity:
      description: Params is not valid
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    TooManyRequests:
      description: Quota exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  schemas:
    ErrorResponse:
      type: object
      required:
        - errors
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorItem'
    ErrorItem:
      type: object
      required:
        - status
        - title
      properties:
        status:
          type: integer
          example: 422
        title:
          type: string
          example: Empty query
        details:
          type: string
          example: ''
    BuildingListResponse:
      type: object
      required:
        - data
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/BuildingResource'
    BuildingResponse:
      type: object
      required:
        - data
      properties:
        data:
          $ref: '#/components/schemas/BuildingResource'
    SuggestResponse:
      type: object
      required:
        - data
      properties:
        data:
          type: array
          items:
            oneOf:
              - $ref: '#/components/schemas/BuildingResource'
              - $ref: '#/components/schemas/StreetResource'
    DistrictListResponse:
      type: object
      required:
        - data
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/DistrictResource'
    BuildingResource:
      type: object
      required:
        - type
        - id
        - attributes
      properties:
        type:
          type: string
          enum:
            - building
        id:
          type: string
          example: '12'
        attributes:
          $ref: '#/components/schemas/BuildingAttributes'
    StreetResource:
      type: object
      required:
        - type
        - id
        - attributes
      properties:
        type:
          type: string
          enum:
            - street
        id:
          type: string
          example: ''
        attributes:
          $ref: '#/components/schemas/StreetAttributes'
    DistrictResource:
      type: object
      required:
        - type
        - id
        - attributes
      properties:
        type:
          type: string
          enum:
            - district
        id:
          type: string
          example: '12'
        attributes:
          $ref: '#/components/schemas/DistrictAttributes'
    BuildingAttributes:
      type: object
      properties:
        osm_id:
          type: string
          example: '100000'
        type:
          type: string
          example: yes
          description: https://wiki.openstreetmap.org/wiki/Key:building
        city:
          type: string
          example: Narva
        district:
          type: string
          example: Pirni
        quarter:
          type: string
          example: Paemurru
        street:
          type: string
          example: Parve
        place:
          type: string
          example: Männi
        house_number:
          type: string
          example: 3a
        name:
          type: string
          example: Narva kohtumaja
        lat:
          type: string
          example: '59.887836403017346'
        lng:
          type: string
          example: '30.324198192236167'
        distance:
          type: string
          example: '114.5143240357325'
    StreetAttributes:
      type: object
      properties:
        osm_id:
          type: string
          example: ''
        city:
          type: string
          example: Narva
        street:
          type: string
          example: Parve
        distance:
          type: string
          example: '114.5143240357325'
    DistrictAttributes:
      type: object
      properties:
        osm_id:
          type: string
          example: '100000'
        name:
          type: string
          example: Narva kohtumaja
        city:
          type: string
          example: Narva
        admin_level:
          type: string
          example: '5'
        type:
          type: string
          example: city
        class:
          type: string
          example: administrative
        polygon:
          type: string
          example: '{"type":"Polygon","coordinates":[[[30.43875485,59.827567153],[30.441120642,59.829373453],[30.443333549,59.829798248]]]}'
  securitySchemes:
    api_key:
      type: apiKey
      name: Authorization
      in: header
