Merge pull request #13570 from abpframework/auto-merge/rel-6-0/1248

Merge branch dev with rel-6.0
pull/13583/head
liangshiwei 3 years ago committed by GitHub
commit e459e0a9bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -120,7 +120,7 @@ Please refer to `ApplicationConfigurationDto` type for all the properties you ca
You can get the application configuration response and set the `ConfigStateService` state value as shown below:
```js
import {ApplicationConfigurationService, ConfigStateService} from '@abp/ng.core';
import {AbpApplicationConfigurationService, ConfigStateService} from '@abp/ng.core';
constructor(private abpApplicationConfigurationService: AbpApplicationConfigurationService, private config: ConfigStateService) {
this.abpApplicationConfigurationService.get().subscribe(config => {

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
@ -48,4 +47,14 @@ public class AbpStringToEnumConverter<T> : JsonConverter<T>
JsonSerializer.Serialize(writer, value, _writeJsonSerializerOptions);
}
public override T ReadAsPropertyName(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return (T)Enum.Parse(typeToConvert, reader.GetString());
}
public override void WriteAsPropertyName(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
{
writer.WritePropertyName(Enum.GetName(typeof(T), value));
}
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using Shouldly;
using Volo.Abp.Json.SystemTextJson.JsonConverters;
@ -26,6 +27,16 @@ namespace Volo.Abp.Json
testClass = JsonSerializer.Deserialize<TestClass>("{\"Day\": 1}", options);
testClass.ShouldNotBeNull();
testClass.Day.ShouldBe(DayOfWeek.Monday);
var dictionary = JsonSerializer.Deserialize<Dictionary<DayOfWeek, string>>("{\"Monday\":\"Mo\"}", options);
dictionary.ShouldNotBeNull();
dictionary.Keys.ShouldContain(DayOfWeek.Monday);
dictionary.Values.ShouldContain("Mo");
dictionary = JsonSerializer.Deserialize<Dictionary<DayOfWeek, string>>("{\"1\":\"Mo\"}", options);
dictionary.ShouldNotBeNull();
dictionary.Keys.ShouldContain(DayOfWeek.Monday);
dictionary.Values.ShouldContain("Mo");
}
[Fact]
@ -45,6 +56,13 @@ namespace Volo.Abp.Json
});
testClassJson.ShouldBe("{\"Day\":1}");
testClassJson = JsonSerializer.Serialize(new Dictionary<DayOfWeek, string>
{
{DayOfWeek.Monday, "Mo"}
}, options);
testClassJson.ShouldBe("{\"Monday\":\"Mo\"}");
}
class TestClass

@ -7,12 +7,18 @@
export class <%= name %>Service {
apiName = '<%= apiName %>';<%
for (let {body, signature} of methods) { %>
<%
const isBlob = body.isBlobMethod() ;
const responseType = isBlob ? "Blob":body.responseType;
%>
<%= camel(signature.name) %> = (<%= serializeParameters(signature.parameters) %>) =>
this.restService.request<<%= body.requestType %>, <%= body.responseType %>>({
method: '<%= body.method %>',<%
this.restService.request<<%= body.requestType %>, <%= responseType %>>({
method: '<%= body.method %>',<%
if (body.responseType === 'string') { %>
responseType: 'text',<% } %>
responseType: 'text',<% } %><%
if (isBlob) { %>
responseType: 'blob',<% } %>
url: <%= body.url %>,<%
if (body.params.length) { %>
params: { <%= body.params.join(', ') %> },<% }

@ -1 +1,2 @@
export const VOLO_REGEX = /^Volo\.Abp\.(Application\.Dtos|ObjectExtending)/;
export const VOLO_REMOTE_STREAM_CONTENT = 'Volo.Abp.Content.IRemoteStreamContent'

@ -4,6 +4,7 @@ import { getParamName } from '../utils/methods';
import { ParameterInBody } from './api-definition';
import { Property } from './model';
import { Omissible } from './util';
import {VOLO_REMOTE_STREAM_CONTENT} from "../constants";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const shouldQuote = require('should-quote');
@ -39,6 +40,7 @@ export class Body {
body?: string;
method: string;
params: string[] = [];
responseTypeWithNamespace: string;
requestType = 'any';
responseType: string;
url: string;
@ -77,6 +79,10 @@ export class Body {
this.setUrlQuotes();
}
isBlobMethod(){
return this.responseTypeWithNamespace === VOLO_REMOTE_STREAM_CONTENT
}
private setUrlQuotes() {
this.url = /{/.test(this.url) ? `\`/${this.url}\`` : `'/${this.url}'`;
}
@ -84,5 +90,5 @@ export class Body {
export type BodyOptions = Omissible<
Omit<Body, 'registerActionParameter'>,
'params' | 'requestType'
'params' | 'requestType' | 'isBlobMethod'
>;

@ -22,6 +22,7 @@ import {
} from './type';
import { eBindingSourceId } from '../enums';
import { camelizeHyphen } from './text';
import {VOLO_REMOTE_STREAM_CONTENT} from "../constants";
export function serializeParameters(parameters: Property[]) {
return parameters.map(p => p.name + p.optional + ': ' + p.type + p.default, '').join(', ');
@ -38,7 +39,8 @@ export function createControllerToServiceMapper({
const name = controller.controllerName;
const namespace = parseNamespace(solution, controller.type);
const actions = Object.values(controller.actions);
const imports = actions.reduce(createActionToImportsReducer(solution, types, namespace), []);
const typeWithoutIRemoteStreamContent = getTypesWithoutIRemoteStreamContent(types)
const imports = actions.reduce(createActionToImportsReducer(solution, typeWithoutIRemoteStreamContent, namespace), []);
imports.push(new Import({ path: '@abp/ng.core', specifiers: ['RestService'] }));
imports.push(new Import({ path: '@angular/core', specifiers: ['Injectable'] }));
sortImports(imports);
@ -48,6 +50,11 @@ export function createControllerToServiceMapper({
};
}
function getTypesWithoutIRemoteStreamContent(types: Record<string, Type>) {
const newType = {...types}
delete newType[VOLO_REMOTE_STREAM_CONTENT]
return newType
}
function sortMethods(methods: Method[]) {
methods.sort((a, b) => (a.signature.name > b.signature.name ? 1 : -1));
}
@ -68,7 +75,8 @@ export function createActionToBodyMapper() {
return ({ httpMethod, parameters, returnValue, url }: Action) => {
const responseType = adaptType(returnValue.typeSimple);
const body = new Body({ method: httpMethod, responseType, url });
const responseTypeWithNamespace = returnValue.typeSimple;
const body = new Body({ method: httpMethod, responseType, url ,responseTypeWithNamespace});
parameters.forEach(body.registerActionParameter);

Loading…
Cancel
Save