{
  "openapi": "3.1.0",
  "info": {
    "title": "Locl API for arrangører",
    "version": "1.0.0",
    "description": "Send arrangementer til locl.no. Nøkkel: invitasjon fra hei@locl.no, eller en egen nøkkel locl_… laget fra invitasjonslenken (kan trekkes tilbake) (Authorization: Bearer). Dokumentasjon: https://locl.no/api",
    "contact": {
      "email": "hei@locl.no",
      "url": "https://locl.no/api"
    }
  },
  "servers": [
    {
      "url": "https://locl.no"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/api/v1/arrangementer": {
      "post": {
        "summary": "Opprett, oppdater eller avlys (upsert på id)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "oneOf": [
                      {
                        "$ref": "#/components/schemas/Arrangement"
                      },
                      {
                        "$ref": "#/components/schemas/JsonLdEvent"
                      }
                    ]
                  },
                  {
                    "type": "array",
                    "maxItems": 100,
                    "items": {
                      "oneOf": [
                        {
                          "$ref": "#/components/schemas/Arrangement"
                        },
                        {
                          "$ref": "#/components/schemas/JsonLdEvent"
                        }
                      ]
                    }
                  },
                  {
                    "type": "object",
                    "properties": {
                      "arrangementer": {
                        "type": "array",
                        "maxItems": 100,
                        "items": {
                          "oneOf": [
                            {
                              "$ref": "#/components/schemas/Arrangement"
                            },
                            {
                              "$ref": "#/components/schemas/JsonLdEvent"
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Minst ett godtatt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Svar"
                }
              }
            }
          },
          "422": {
            "description": "Alle avvist (se resultat[].feil)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Svar"
                }
              }
            }
          },
          "400": {
            "description": "Ugyldig JSON eller tom",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "401": {
            "description": "Mangler eller ugyldig nøkkel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "403": {
            "description": "Utløpt nøkkel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "413": {
            "description": "Over 100 arrangementer eller 1 MB",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "429": {
            "description": "Grense nådd (300/døgn, 60/min)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          }
        }
      },
      "get": {
        "summary": "List egne arrangementer",
        "parameters": [
          {
            "name": "fra",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "Fra og med start (standard: i går)"
          }
        ],
        "responses": {
          "200": {
            "description": "Liste",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "arrangor": {
                      "type": "string"
                    },
                    "antall": {
                      "type": "integer"
                    },
                    "arrangementer": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Ugyldig nøkkel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "403": {
            "description": "Utløpt nøkkel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/arrangementer/{id}": {
      "delete": {
        "summary": "Avlys (merkes «Avlyst», slettes ikke)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Avlyst",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Resultat"
                }
              }
            }
          },
          "404": {
            "description": "Finnes ikke",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "401": {
            "description": "Ugyldig nøkkel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          },
          "403": {
            "description": "Utløpt nøkkel",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feil"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Invitasjonskoden (etter invitasjon= i lenken)"
      }
    },
    "schemas": {
      "Arrangement": {
        "type": "object",
        "required": [
          "id",
          "tittel",
          "start",
          "lenke"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[A-Za-z0-9._:@+=-]{1,120}$",
            "description": "Arrangørens egen stabile id. Samme id oppdaterer."
          },
          "tittel": {
            "type": "string",
            "minLength": 3,
            "maxLength": 120
          },
          "start": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 med tidssone. Uten sone = Europe/Oslo. Bare dato avvises."
          },
          "slutt": {
            "type": "string",
            "format": "date-time"
          },
          "sted": {
            "type": "string",
            "maxLength": 100,
            "description": "Påkrevd hvis adresse mangler"
          },
          "adresse": {
            "type": "string",
            "maxLength": 150
          },
          "by": {
            "type": "string",
            "description": "By-id eller navn på locl.no (oslo, bergen …). Ellers fra adressen."
          },
          "beskrivelse": {
            "type": "string",
            "maxLength": 1500,
            "description": "Ren tekst; HTML fjernes"
          },
          "kategori": {
            "type": "string",
            "enum": [
              "music",
              "theatre",
              "art",
              "film",
              "talk",
              "family",
              "food",
              "market",
              "sports",
              "outdoor",
              "nightlife",
              "workshop",
              "shopping",
              "business",
              "social",
              "motor",
              "free"
            ]
          },
          "lenke": {
            "type": "string",
            "format": "uri",
            "description": "http(s): arrangementets side hos arrangøren"
          },
          "billettlenke": {
            "type": "string",
            "format": "uri"
          },
          "bilde": {
            "type": "string",
            "format": "uri"
          },
          "pris_fra": {
            "type": "number",
            "minimum": 0,
            "maximum": 99999
          },
          "gratis": {
            "type": "boolean"
          },
          "avlyst": {
            "type": "boolean",
            "description": "true avlyser, false gjenoppretter, utelatt = uendret"
          }
        }
      },
      "JsonLdEvent": {
        "type": "object",
        "description": "schema.org/Event som JSON-LD (name, startDate, endDate, location, url, offers, image, eventStatus, identifier)",
        "required": [
          "name",
          "startDate"
        ],
        "properties": {
          "@type": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "startDate": {
            "type": "string"
          }
        },
        "additionalProperties": true
      },
      "Resultat": {
        "type": "object",
        "properties": {
          "id": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "opprettet",
              "oppdatert",
              "uendret",
              "avlyst",
              "avvist"
            ]
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "feil": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "felt": {
                  "type": "string"
                },
                "kode": {
                  "type": "string"
                },
                "no": {
                  "type": "string"
                },
                "en": {
                  "type": "string"
                }
              }
            }
          },
          "merknader": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Merknader: uten_posisjon (fant ikke posisjon), venter_godkjenning (prøvetid: de tre første arrangementene fra en ny arrangør modereres før publisering), og feltmerknader fra lesingen."
          }
        }
      },
      "Feil": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          },
          "melding": {
            "type": "string",
            "description": "Norsk"
          },
          "message": {
            "type": "string",
            "description": "English"
          }
        },
        "required": [
          "error",
          "melding",
          "message"
        ]
      },
      "Svar": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "oppsummering": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "resultat": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Resultat"
            }
          },
          "grense": {
            "type": "object",
            "properties": {
              "per_dogn": {
                "type": "integer"
              },
              "igjen": {
                "type": "integer"
              }
            }
          }
        }
      }
    }
  }
}
