Skip to content

Commit 5cb072b

Browse files
committed
feat!: utkast til første versjon
1 parent 3d740ea commit 5cb072b

14 files changed

Lines changed: 1017 additions & 5 deletions

File tree

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @statens-pensjonskasse/team-rettighet
1+
* @statens-pensjonskasse/team-rettighet

.github/renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"local>statens-pensjonskasse/renovate-presets-internal:daily-automerge-non-major"
5+
]
6+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Build Maven Library
2+
3+
on:
4+
push:
5+
workflow_dispatch:
6+
7+
jobs:
8+
build-and-publish:
9+
uses: statens-pensjonskasse/github-actions-library/.github/workflows/build-library-maven.yaml@a2bc06ac35932796354f31ce92d0fc516b27a20b # v1.44.15
10+
permissions:
11+
contents: write
12+
packages: write
13+
secrets: inherit
14+
with:
15+
java-version: '21'
16+
slack-channel: '#rettighet-ci'

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea
2+
*.iml
3+
target
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
wrapperVersion=3.3.4
2+
distributionType=only-script
3+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.11/apache-maven-3.9.11-bin.zip

LICENSE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Copyright 2025 Statens pensjonskasse
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of
4+
this software and associated documentation files (the “Software”), to deal in
5+
the Software without restriction, including without limitation the rights to
6+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
7+
the Software, and to permit persons to whom the Software is furnished to do so,
8+
subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
15+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
16+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,114 @@
11
# felles-openapi-customizer-lib
2-
felles-openapi-customizer-lib eies og forvaltes av team-rettighet
2+
3+
Takes an OpenAPI specification and customizes all paths with the standard
4+
security scheme and headers typically used in SPK.
5+
6+
These headers are normally omitted from the OpenAPI specification for
7+
practical purposes and provided to the client and consumed by the server
8+
using implicit infrastructure libraries such as `felles-outbound-lib`. This
9+
class allows adding these headers back in, in order for the server to show a
10+
complete specification using SwaggerUI.
11+
12+
There are two standard security schemes typically supported in SPK:
13+
14+
1. Token based authentication using a security token.
15+
2. Basic authentication using the employee's username and password.
16+
17+
There are three standard headers supported in SPK:
18+
19+
1. `X-Application-Id` which contains the caller's application identity.
20+
2. `X-Correlation-Id` which correlates the invocation across systems.
21+
3. `X-Request-Origin` which contains the origin's application identity.
22+
23+
## Usage
24+
25+
### Maven
26+
27+
Add the following dependency to your project:
28+
29+
```xml
30+
<!-- add this to your pom.xml -->
31+
<dependency>
32+
<groupId>no.spk.felles</groupId>
33+
<artifactId>felles-openapi-customizer-lib</artifactId>
34+
<version>0.0.1-SNAPSHOT</version>
35+
</dependency>
36+
```
37+
38+
### Customize an existing OpenAPI-spec (contract-first)
39+
40+
Takes the filename of an OpenAPI specification on classpath as input,
41+
reads the file, customizes it with the given security schemes and
42+
headers, and returns it as an `OpenAPI` object.
43+
44+
The `OpenAPI` object can be provided to Spring as a `@Bean` in order for
45+
documentation providers such as Springdoc to show the specification on
46+
the server using SwaggerUI.
47+
48+
```kotlin
49+
@Bean
50+
fun createOpenAPI() {
51+
val customizer = OpenAPICustomizer(
52+
customizeWithSecuritySchemes = true,
53+
customizeWithStandardHeaders = true,
54+
)
55+
return customizer.readAndCustomizeOpenAPI("/openapi/openapi.yaml")
56+
}
57+
```
58+
59+
Note that the above requires the OpenAPI specification to be unpacked
60+
into `/openapi/openapi.yaml` on the classpath.
61+
62+
This is well-suited for OpenAPI specifications written contract-first,
63+
where the specification is available as a file.
64+
65+
If using Springdoc, it is also advisable to disable scanning of packages
66+
adding `springdoc.packages-to-scan=none` to Spring Boot's configuration,
67+
otherwise annotated resources might show up twice in the specification.
68+
69+
### Customize a generated OpenAPI-spec (code-first)
70+
71+
Customizes an existing OpenAPI specification with the given security
72+
schemes and headers.
73+
74+
The `OpenAPI` object can be provided to Spring as a `@Bean` in order for
75+
documentation providers such as Springdoc to show the specification on
76+
the server using SwaggerUI.
77+
78+
```kotlin
79+
@Bean
80+
fun createOpenAPI() {
81+
val customizer = OpenAPICustomizer(
82+
customizeWithSecuritySchemes = true,
83+
customizeWithStandardHeaders = true,
84+
)
85+
val generatedOpenAPI = OpenAPI()
86+
return customizer.customizeOpenAPI(generatedOpenAPI)
87+
}
88+
```
89+
90+
This is well-suited for OpenAPI specifications that are generated from
91+
annotated source code, after which these customizations are applied.
92+
93+
## Development
94+
95+
### Requirements
96+
97+
Requirements to build the project on your machine:
98+
99+
* JDK
100+
* Maven
101+
102+
### Build
103+
104+
Run the following command to build the project:
105+
106+
```shell
107+
mvn clean install
108+
```
109+
110+
### Branch and release
111+
112+
1. Branch from `main`.
113+
2. Create a pull-request and merge to `main`.
114+
3. This will release a new version.

0 commit comments

Comments
 (0)