Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @statens-pensjonskasse/team-rettighet
* @statens-pensjonskasse/team-rettighet
6 changes: 6 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"local>statens-pensjonskasse/renovate-presets-internal:daily-automerge-non-major"
]
}
16 changes: 16 additions & 0 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build Maven Library

on:
push:
workflow_dispatch:

jobs:
build-and-publish:
uses: statens-pensjonskasse/github-actions-library/.github/workflows/build-library-maven.yaml@a2bc06ac35932796354f31ce92d0fc516b27a20b # v1.44.15
permissions:
contents: write
packages: write
secrets: inherit
with:
java-version: '21'
slack-channel: '#rettighet-ci'
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
*.iml
target
3 changes: 3 additions & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
wrapperVersion=3.3.4
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright 2025 Statens pensjonskasse

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.
114 changes: 113 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,114 @@
# felles-openapi-customizer-lib
felles-openapi-customizer-lib eies og forvaltes av team-rettighet

Takes an OpenAPI specification and customizes all paths with the standard
security scheme and headers typically used in SPK.

These headers are normally omitted from the OpenAPI specification for
practical purposes and provided to the client and consumed by the server
using implicit infrastructure libraries such as `felles-outbound-lib`. This
class allows adding these headers back in, in order for the server to show a
complete specification using SwaggerUI.

There are two standard security schemes typically supported in SPK:

1. Token based authentication using a security token.
2. Basic authentication using the employee's username and password.

There are three standard headers supported in SPK:

1. `X-Application-Id` which contains the caller's application identity.
2. `X-Correlation-Id` which correlates the invocation across systems.
3. `X-Request-Origin` which contains the origin's application identity.

## Usage

### Maven

Add the following dependency to your project:

```xml
<!-- add this to your pom.xml -->
<dependency>
<groupId>no.spk.felles</groupId>
<artifactId>felles-openapi-customizer-lib</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
```

### Customize an existing OpenAPI-spec (contract-first)

Takes the filename of an OpenAPI specification on classpath as input,
reads the file, customizes it with the given security schemes and
headers, and returns it as an `OpenAPI` object.

The `OpenAPI` object can be provided to Spring as a `@Bean` in order for
documentation providers such as Springdoc to show the specification on
the server using SwaggerUI.

```kotlin
@Bean
fun createOpenAPI() {
val customizer = OpenAPICustomizer(
customizeWithSecuritySchemes = true,
customizeWithStandardHeaders = true,
)
return customizer.readAndCustomizeOpenAPI("/openapi/openapi.yaml")
}
```

Note that the above requires the OpenAPI specification to be unpacked
into `/openapi/openapi.yaml` on the classpath.

This is well-suited for OpenAPI specifications written contract-first,
where the specification is available as a file.

If using Springdoc, it is also advisable to disable scanning of packages
adding `springdoc.packages-to-scan=none` to Spring Boot's configuration,
otherwise annotated resources might show up twice in the specification.

### Customize a generated OpenAPI-spec (code-first)

Customizes an existing OpenAPI specification with the given security
schemes and headers.

The `OpenAPI` object can be provided to Spring as a `@Bean` in order for
documentation providers such as Springdoc to show the specification on
the server using SwaggerUI.

```kotlin
@Bean
fun createOpenAPI() {
val customizer = OpenAPICustomizer(
customizeWithSecuritySchemes = true,
customizeWithStandardHeaders = true,
)
val generatedOpenAPI = OpenAPI()
return customizer.customizeOpenAPI(generatedOpenAPI)
}
```

This is well-suited for OpenAPI specifications that are generated from
annotated source code, after which these customizations are applied.

## Development

### Requirements

Requirements to build the project on your machine:

* JDK
* Maven

### Build

Run the following command to build the project:

```shell
mvn clean install
```

### Branch and release

1. Branch from `main`.
2. Create a pull-request and merge to `main`.
3. This will release a new version.
Loading