Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nestjs/swagger
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 11.0.6
Choose a base ref
...
head repository: nestjs/swagger
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 11.0.7
Choose a head ref

Commits on Feb 28, 2025

  1. chore(deps): update nest monorepo to v11.0.11 (#3325)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Feb 28, 2025
    Copy the full SHA
    9a43ede View commit details

Commits on Mar 1, 2025

  1. chore(deps): update dependency @types/lodash to v4.17.16 (#3327)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 1, 2025
    Copy the full SHA
    8c9bcaf View commit details
  2. chore(deps): update dependency @types/node to v22.13.8 (#3328)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 1, 2025
    Copy the full SHA
    9b2918e View commit details

Commits on Mar 3, 2025

  1. chore(deps): update dependency prettier to v3.5.3 (#3330)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 3, 2025
    Copy the full SHA
    9fefc86 View commit details
  2. Update README.md

    kamilmysliwiec authored Mar 3, 2025
    Copy the full SHA
    93e51db View commit details
  3. chore(deps): update dependency @types/node to v22.13.9 (#3331)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 3, 2025
    Copy the full SHA
    86f87e9 View commit details

Commits on Mar 4, 2025

  1. chore(deps): update dependency typescript-eslint to v8.26.0 (#3332)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 4, 2025
    Copy the full SHA
    7aea964 View commit details
  2. chore(deps): update dependency typescript to v5.8.2 (#3329)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 4, 2025
    Copy the full SHA
    2413f57 View commit details

Commits on Mar 7, 2025

  1. chore(deps): update dependency eslint-config-prettier to v10.1.1 (#3336)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 7, 2025
    Copy the full SHA
    757268a View commit details
  2. chore(deps): update commitlint monorepo to v19.8.0 (#3337)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 7, 2025
    Copy the full SHA
    bb58670 View commit details

Commits on Mar 8, 2025

  1. chore(deps): update eslint monorepo to v9.22.0 (#3340)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 8, 2025
    Copy the full SHA
    c4940d4 View commit details
  2. chore(deps): update dependency @types/node to v22.13.10 (#3341)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 8, 2025
    Copy the full SHA
    a12a7e8 View commit details

Commits on Mar 10, 2025

  1. Copy the full SHA
    fed8c1a View commit details
  2. chore(deps): update dependency typescript-eslint to v8.26.1 (#3344)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 10, 2025
    Copy the full SHA
    a29f198 View commit details

Commits on Mar 12, 2025

  1. chore(deps): update dependency lint-staged to v15.5.0 (#3345)

    Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
    renovate[bot] authored Mar 12, 2025
    Copy the full SHA
    c5c8ab4 View commit details

Commits on Mar 17, 2025

  1. Copy the full SHA
    da70f3a View commit details
  2. Copy the full SHA
    db3f589 View commit details

Commits on Mar 19, 2025

  1. Merge pull request #3347 from flovouin/fix-self-required

    Fix `selfRequired: false` not making an object-type property optional
    kamilmysliwiec authored Mar 19, 2025
    Copy the full SHA
    8e3cb90 View commit details
  2. Merge pull request #3323 from nestjs/renovate/swagger-ui-dist-5.x

    fix(deps): update dependency swagger-ui-dist to v5.20.1
    kamilmysliwiec authored Mar 19, 2025
    Copy the full SHA
    acaf1df View commit details
  3. Copy the full SHA
    d817ca8 View commit details
  4. Copy the full SHA
    d2965f9 View commit details
Showing with 339 additions and 245 deletions.
  1. +0 −1 README.md
  2. +24 −0 e2e/api-spec.json
  3. +8 −1 e2e/src/cats/classes/cat.class.ts
  4. +17 −0 e2e/src/cats/dto/create-cat.dto.ts
  5. +8 −0 e2e/validate-schema.e2e-spec.ts
  6. +4 −4 lib/services/schema-object-factory.ts
  7. +10 −2 lib/swagger-explorer.ts
  8. +15 −3 lib/swagger-scanner.ts
  9. +235 −216 package-lock.json
  10. +18 −18 package.json
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
24 changes: 24 additions & 0 deletions e2e/api-spec.json
Original file line number Diff line number Diff line change
@@ -1463,6 +1463,23 @@
}
}
},
"rawDefinition": {
"type": "object",
"properties": {
"name": {
"type": "string",
"example": "ErrorName"
},
"status": {
"type": "number",
"example": 400
}
},
"required": [
"name",
"status"
]
},
"enumWithDescription": {
"enum": [
"A",
@@ -1525,6 +1542,7 @@
"createdAt",
"urls",
"options",
"rawDefinition",
"enumWithDescription",
"enum",
"enumArr",
@@ -1600,6 +1618,12 @@
"status"
]
},
"optionalRawDefinition": {
"type": "object",
"additionalProperties": {
"type": "boolean"
}
},
"enum": {
"type": "string",
"enum": [
9 changes: 8 additions & 1 deletion e2e/src/cats/classes/cat.class.ts
Original file line number Diff line number Diff line change
@@ -60,7 +60,14 @@ export class Cat {
required: ['name', 'status'],
selfRequired: true
})
rawDefinition?: Record<string, any>;
rawDefinition: Record<string, any>;

@ApiProperty({
type: 'object',
additionalProperties: { type: 'boolean' },
selfRequired: false
})
optionalRawDefinition?: Record<string, boolean>;

@ApiProperty({
enum: LettersEnum
17 changes: 17 additions & 0 deletions e2e/src/cats/dto/create-cat.dto.ts
Original file line number Diff line number Diff line change
@@ -44,6 +44,23 @@ export class CreateCatDto {
})
readonly options?: Record<string, any>[];

@ApiProperty({
type: 'object',
properties: {
name: {
type: 'string',
example: 'ErrorName'
},
status: {
type: 'number',
example: 400
}
},
required: ['name', 'status'],
selfRequired: true
})
rawDefinition: Record<string, any>;

@ApiProperty({
description: 'Enum with description'
})
8 changes: 8 additions & 0 deletions e2e/validate-schema.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {
OpenAPIObject,
SwaggerModule
} from '../lib';
import { SchemaObject } from '../lib/interfaces/open-api-spec.interface';
import { ApplicationModule } from './src/app.module';
import { Cat } from './src/cats/classes/cat.class';
import { TagDto } from './src/cats/dto/tag.dto';
@@ -222,4 +223,11 @@ describe('Validate OpenAPI schema', () => {
}
});
});

it('should not add optional properties to required list', async () => {
const document = SwaggerModule.createDocument(app, options);
const required = (document.components?.schemas?.Cat as SchemaObject)
?.required;
expect(required).not.toContain('optionalRawDefinition');
});
});
8 changes: 4 additions & 4 deletions lib/services/schema-object-factory.ts
Original file line number Diff line number Diff line change
@@ -268,10 +268,10 @@ export class SchemaObjectFactory {
};

const typeDefinitionRequiredFields = propertiesWithType
.filter(
(property) =>
(property.required != false && !Array.isArray(property.required)) ||
('selfRequired' in property && property.selfRequired != false)
.filter((property) =>
'selfRequired' in property
? property.selfRequired != false
: property.required != false && !Array.isArray(property.required)
)
.map((property) => property.name);

12 changes: 10 additions & 2 deletions lib/swagger-explorer.ts
Original file line number Diff line number Diff line change
@@ -93,7 +93,12 @@ export class SwaggerExplorer {
? `${controllerKey}_${methodKey}_from_${fieldKey}`
: `${methodKey}_from_${fieldKey}`;

constructor(private readonly schemaObjectFactory: SchemaObjectFactory) {}
constructor(
private readonly schemaObjectFactory: SchemaObjectFactory,
private readonly options: {
httpAdapterType?: string;
} = {}
) {}

public exploreController(
wrapper: InstanceWrapper<Controller>,
@@ -439,7 +444,10 @@ export class SwaggerExplorer {
let pathWithParams = '';

try {
let normalizedPath = LegacyRouteConverter.tryConvert(path);
let normalizedPath = LegacyRouteConverter.tryConvert(path, {
// Skip logs for Fastify as it has different rules for wildcard routes
logs: this.options.httpAdapterType !== 'fastify'
});
// Optional segment groups are not supported by Fastify
normalizedPath = normalizedPath.replace(/::/g, '\\:');
normalizedPath = normalizedPath.replace(/\[:\]/g, '\\:');
18 changes: 15 additions & 3 deletions lib/swagger-scanner.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ export class SwaggerScanner {
new ModelPropertiesAccessor(),
new SwaggerTypesMapper()
);
private readonly explorer = new SwaggerExplorer(this.schemaObjectFactory);
private explorer: SwaggerExplorer | undefined;

public scanApplication(
app: INestApplication,
@@ -44,8 +44,11 @@ export class SwaggerScanner {
autoTagControllers = true
} = options;

const container = (app as any).container as NestContainer;
const internalConfigRef = (app as any).config as ApplicationConfig;
const untypedApp = app as any;
const container = untypedApp.container as NestContainer;
const internalConfigRef = untypedApp.config as ApplicationConfig;
const httpAdapterType = app.getHttpAdapter().getType();
this.initializeSwaggerExplorer(httpAdapterType);

const modules: Module[] = this.getModules(
container.getModules(),
@@ -169,4 +172,13 @@ export class SwaggerScanner {
);
return modulePath ?? Reflect.getMetadata(MODULE_PATH, metatype);
}

private initializeSwaggerExplorer(httpAdapterType: string) {
if (this.explorer) {
return;
}
this.explorer = new SwaggerExplorer(this.schemaObjectFactory, {
httpAdapterType
});
}
}
Loading