LogoLogo
  • Technical Direction
  • Technical overview
    • Technical Implementation
    • API Design Guide
      • Data Definitions and Standards
      • Data Transfer Objects
      • Documentation
      • Environments
      • Error Handling
      • Example API Service
      • GraphQL Naming Conventions
      • Methods
      • Naming Conventions
      • Once Only Principle
      • Pagination
      • Resource Oriented Design
      • REST Request
      • REST Response
      • Security
      • Versioning
    • Ísland.is Public Web Data Flow
    • Code Reviews
    • Code Standards
    • Monorepo
    • Project Management
    • Teamwork
    • Architectural Decision Records
      • Use Markdown Architectural Decision Records
      • Use NX
      • Continuous Integration
      • CSS
      • Branching and Release Strategy
      • Error Tracking and Monitoring
      • What API Management Tool to Consider
      • Viskuausan Static Site Generator
      • Use OAuth 2.0 and OpenID Connect As Protocols for Authentication and Authorization
      • Unified Naming Strategy for Files and Directories
      • CMS
      • Open Source License
      • What Chart Library Should We Use Across Island.is?
      • What Feature Flag Service/application Should We Use at Island.is?
      • Logging, Monitoring and APM Platform
      • ADR Template
    • Log Management Policy
  • Products
    • Island.is Authentication Service
      • Terminology
      • Integration Options
      • Authentication Flows
      • Authorising API Endpoints
      • Session Lifecycle
      • Scopes and Tokens
      • Delegations
      • Configuration
      • Tools and Examples
      • Environments
      • Test IAS with Postman
      • Using the IAS admin portal
    • Notifications / Hnipp
      • New Notification Setup Guide
      • Notifications service workflow overview
      • Email notifications
    • Pósthólfið
      • Security Checklist
      • Introduction
      • Skjalatilkynning API
      • Skjalaveita API
      • Sequence Diagram
      • Interfaces
    • Straumurinn (X-Road)
      • Architecture Guidelines for Service Providers and Consumers
      • Setting up an X-Road Security Server
        • Network Configuration
      • X-Road - Uppfærsla á öryggisþjónum
      • Straumurinn - Notkun og umsýsla
      • X-Road Central - current version
  • Development
    • Getting Started
    • Generating a New Project
    • Definition of done
    • Devops
      • Continuous Delivery
      • Database
      • Dockerizing
      • Environment Setup
      • Logging
      • Metrics
      • NextJS Custom Server
      • Observability
      • Operations Base Principles
      • Security
      • Service Configuration
      • Support
    • AWS Secrets
    • Feature Flags
    • Documentation Contributions
    • Defining Monorepo Boundaries With Tags
    • OpenAPI
    • Code Generation
    • Workspace Settings (Deprecated)
    • External Contributions
  • REFERENCE
    • Problems
      • 400 Validation Failed
      • 400 Attempt Failed
      • 403 Bad Subject
      • 400 500 Template API Error
    • Glossary
  • Misc
    • Guide: Adding a Payment Step to an Application
    • Guide: Enable Organisations to Make Requests to an Application
    • README Template
Powered by GitBook
On this page
  • Download the OpenAPI document
  • Setting server property
  • Configuring SwaggerUI dependencies for esbuild

Was this helpful?

  1. Development

OpenAPI

PreviousDefining Monorepo Boundaries With TagsNextCode Generation

Last updated 1 year ago

Was this helpful?

Our services are implemented using the NestJS framework which includes SwaggerUI/OpenAPI support. We should always include an OpenAPI document for our public REST services and use the SwaggerUI to make it accessible.

Our infra-nest-server.bootstrap accepts a parameter of type OpenAPIObject which is used to configure the SwaggerUI. The service should set the base properties in openApi.ts and then use on controllers, methods, models and DTOs.

Example of openApi.ts

import { DocumentBuilder } from '@nestjs/swagger'

export const openApi = new DocumentBuilder()
  .setTitle('IdentityServer Public API')
  .setDescription(
    'Public API for IdentityServer.\n\n\nThe swagger document can be downloaded by appending `-json` to the last path segment.',
  )
  .addServer(process.env.PUBLIC_URL ?? 'http://localhost:3370')
  .setVersion('1.0')
  .build()

For more details about OpenAPI support in NestJS read their .

Download the OpenAPI document

The SwaggerUI makes the document itself accessible on the same path with -json added. For example if the SwaggerUI is rendered on https://innskra.island.is/api/swagger then the document can be downloaded from https://innskra.island.is/api/swagger-json.

As the SwaggerUI is missing a download button, we should include a short message in the description field, how the document can be downloaded. This helps our service consumers to get the document for client and model generation.

Setting server property

In the openApi.ts example above, we add the server property. To get the environment specific host details we use the environment variable PUBLIC_URL. This variable needs to be set in the service infra dsl (or helm chart if it's not yet part of the monorepo infra namespaces).

Configuring SwaggerUI dependencies for esbuild

As we use esbuild to build and bundle our APIs, we need to add swagger-ui-dist to the external list in esbuild.json for our SwaggerUI to work in a production build.

NestJS OpenAPI Decorators
docs