Skip to content

Commit

Permalink
fix: the bug of implementation of #386
Browse files Browse the repository at this point in the history
  • Loading branch information
horiuchi committed Feb 5, 2020
1 parent 779f373 commit 436de28
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/core/schemaConvertor.ts
Expand Up @@ -84,7 +84,7 @@ export default class SchemaConvertor {

public startInterfaceNest(id: SchemaId): void {
const processor = this.processor;
if (processor.indentLevel === 0 && this.ns) {
if (processor.indentLevel === 0 && (this.ns == null || this.ns.length > 0)) {
processor.output('declare ');
} else {
processor.output('export ');
Expand All @@ -100,7 +100,7 @@ export default class SchemaConvertor {

public outputExportType(id: SchemaId): void {
const processor = this.processor;
if (processor.indentLevel === 0 && this.ns) {
if (processor.indentLevel === 0 && (this.ns == null || this.ns.length > 0)) {
processor.output('declare ');
} else {
processor.output('export ');
Expand Down
2 changes: 1 addition & 1 deletion test/simple_schema_test.ts
Expand Up @@ -25,7 +25,7 @@ describe('simple schema test', () => {
};
const result = await dtsgenerator({ contents: [schema] });

const expected = `export interface NoNamespace {
const expected = `declare interface NoNamespace {
}
`;
assert.equal(result, expected, result);
Expand Down
4 changes: 2 additions & 2 deletions test/snapshots/json-schema-draft-04/apimeta/_expected.d.ts
@@ -1,13 +1,13 @@
/**
* ApiBaseObject of a record
*/
export interface ApiBaseObject {
declare interface ApiBaseObject {
first?: string;
}
/**
* Metadata of a record
*/
export interface ApiMetadata {
declare interface ApiMetadata {
serverOperation?: "I" | "U" | "D";
test?: ApiBaseObject;
}
7 changes: 7 additions & 0 deletions test/snapshots/openapi-v3/empty_response/_expected.d.ts
@@ -0,0 +1,7 @@
declare namespace Components {
namespace Schemas {
export interface Object {
id?: string;
}
}
}
22 changes: 22 additions & 0 deletions test/snapshots/openapi-v3/empty_response/empty_response.yaml
@@ -0,0 +1,22 @@
openapi: "3.0.2"
info:
title: empty response
version: v0.1
components:
schemas:
object:
type: object
properties:
id:
type: string
responses:
created:
description: 'object created'
paths:
post:
requestBody:
application/json:
$ref: '#/components/schemas/object'
responses:
204:
$ref: '#/components/responses/created'
12 changes: 6 additions & 6 deletions test/snapshots/openapi-v3/petstore-no-namespace/_expected.d.ts
@@ -1,8 +1,8 @@
declare interface Error {
export interface Error {
code: number; // int32
message: string;
}
declare interface NewPet {
export interface NewPet {
name: string;
tag?: string;
}
Expand All @@ -11,19 +11,19 @@ declare namespace Parameters {
export type Limit = number; // int32
export type Tags = string[];
}
declare interface PathParameters {
export interface PathParameters {
id: Parameters.Id; // int64
}
declare interface Pet {
export interface Pet {
name: string;
tag?: string;
id: number; // int64
}
declare interface QueryParameters {
export interface QueryParameters {
tags?: Parameters.Tags;
limit?: Parameters.Limit; // int32
}
declare type RequestBody = NewPet;
export type RequestBody = NewPet;
declare namespace Responses {
export type $200 = Pet;
export type Default = Error;
Expand Down

0 comments on commit 436de28

Please sign in to comment.