小编1Z1*_*Z10的帖子

Flask:如何自动化 OpenAPI v3 文档?

我需要记录一个用纯 Flask 2 编写的 API,并且我正在寻找执行此操作的统一方法。我找到了不同的可行解决方案,但作为 Python 和 Flask 的新手,我无法在其中进行选择。我找到的解决方案是:

为了分离不同的 API 端点,我使用 Flask 蓝图。MWE的结构如下:

项目结构

我首先定义了两个简单的域对象:AuthorBook

# author.py
class Author:
    def __init__(self, id: str, name: str):
        self.id = id
        self.name = name

# book.py
class Book:
    def __init__(self, id: str, name: str):
        self.id = id
        self.name = name
Run Code Online (Sandbox Code Playgroud)

接下来,我使用两个单独的蓝图为它们创建了一个简单的 GET 端点。

# author_apy.py
import json

from flask import Blueprint, Response

from domain.author import Author

author = Blueprint("author", __name__, url_prefix="/authors")


@author.get("/")
def authors():
    authors: list[Author] …
Run Code Online (Sandbox Code Playgroud)

python flask python-3.x openapi

14
推荐指数
2
解决办法
1万
查看次数

Docker:如何在 /var/lib/docker/overlay2/* 空间释放/限制卷/层?

在 CentOS 7 服务器上,由于“未知”docker 卷,我的空间不足,我无法链接到相应的容器,以评估是否可以删除它。

通过运行df -h我发现/var/lib/docker/overlay2下正在使用大量空间

[root@dev /]# df -h
Filesystem                  Size  Used Avail Use% Mounted on
/dev/mapper/vg_sys-lv_root   20G   19G     0 100% /
devtmpfs                    3.9G     0  3.9G   0% /dev
tmpfs                       3.9G     0  3.9G   0% /dev/shm
tmpfs                       3.9G   50M  3.8G   2% /run
tmpfs                       3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                   190M  147M   30M  84% /boot
tmpfs                       783M     0  783M   0% /run/user/0
overlay                      20G   19G     0 100% /var/lib/docker/overlay2/df91b034e8daa4cfd70f43d1b430ef3d071921b53c2c272e2607176e229588d0/merged
shm                          64M     0   64M   0% /var/lib/docker/containers/9a282dc54d83ed5b218e4c395a3d199b16eb032335cd5c310b7db35052186b7b/mounts/shm
overlay                      20G   19G     0 …
Run Code Online (Sandbox Code Playgroud)

docker

7
推荐指数
0
解决办法
1594
查看次数

Kafkacat:如何删除主题或其所有消息?

我正在寻找一种使用kafkacat. 是否可能或唯一的方法是通过此处列出的脚本?

bin/kafka-topics.sh --zookeeper localhost:2181 --delete --topic mytopic
Run Code Online (Sandbox Code Playgroud)

apache-kafka kafkacat

7
推荐指数
1
解决办法
5265
查看次数

WebFlux DataBufferLimitException: Part headers exceeded the memory usage limit of 8192 bytes

When uploading a csv file and a JSON object at the following endpoint

@PostMapping(value = "dataset/rows/query", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Mono<List<Integer>> getRowsByQuery(@RequestPart("dataset") Mono<FilePart> file, 
                                   @RequestPart("query") QueryDTO query){
    return Mono.just(new ArrayList<>());
}
Run Code Online (Sandbox Code Playgroud)

I get the following error:

2020-12-17 12:25:05.142 ERROR 195281 --- [or-http-epoll-3] a.w.r.e.AbstractErrorWebExceptionHandler : [d418565e-17]  500 Server Error for HTTP POST "/dataset/rows/query"

org.springframework.core.io.buffer.DataBufferLimitException: Part headers exceeded the memory usage limit of 8192 bytes
    at org.springframework.http.codec.multipart.MultipartParser$HeadersState.onNext(MultipartParser.java:360) ~[spring-web-5.3.1.jar:5.3.1]
    Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: 
Error has been observed at the following site(s):
    |_ checkpoint ? org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain] …
Run Code Online (Sandbox Code Playgroud)

java netty project-reactor spring-webflux

7
推荐指数
1
解决办法
1098
查看次数

org.h2.jdbc.JdbcSQLException:无法解析"TIMESTAMP"常量"$ {now}";

几天之内,我一直在努力解决这个问题而没有真正理解它背后的原因.使用Liquibase,PostgreSQL和H2DB(用于测试).Liquibase在使用PostgreSQL时运行正常,但是一旦我需要运行在H2DB上执行的测试,它们就会因为$ {now}属性的解析异常而失败,就好像它没有被有效值替换一样(至少我是这么认为的).这是我创建表的变更集:

<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
                        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">

    <property name="now" value="now()" dbms="h2"/>

    <property name="now" value="current_timestamp" dbms="postgresql"/>

    <property name="floatType" value="float4" dbms="postgresql, h2"/>
    <property name="floatType" value="float" dbms="mysql, oracle, mssql"/>

    <!--
        Added the entity Container.
    -->
    <changeSet id="20180424154826-1" author="developer">
        <createTable tableName="container">
            <column name="id" type="bigint" autoIncrement="${autoIncrement}">
                <constraints primaryKey="true" nullable="false"/>
            </column>
            <column name="name" type="varchar(255)">
                <constraints nullable="false" />
            </column>

            <column name="description" type="varchar(2000)">
                <constraints nullable="true" />
            </column>

            <column name="container_type" type="varchar(255)">
                <constraints nullable="true" />
            </column>

            <column name="created" type="timestamp">
                <constraints nullable="true" />
            </column>
        </createTable> …
Run Code Online (Sandbox Code Playgroud)

timestamp h2 liquibase

6
推荐指数
1
解决办法
1711
查看次数

TypeScript:地图的键(对象)不起作用

在检查地图是否已经具有对象作为键时遇到一些麻烦。

例如

const myMap: Map<MyObject1, MyObject2> = new Map<MyObject1, MyObject2>();
Run Code Online (Sandbox Code Playgroud)

我还在MyObject1类中定义了一个equals函数

equals(other: ThreatAgentMgm): boolean {
    return other.id === this.id;
}
Run Code Online (Sandbox Code Playgroud)

myMap.has(myObject1)总是错误的。我读了has方法基于===运算符,我应该在MyObject1类中定义其他内容吗?

dictionary equality typescript

6
推荐指数
1
解决办法
3123
查看次数

Angular Material 5:选择(单击)选项卡后如何调用函数?

我有以下html代码

<mat-tab label="Regular" (selectChange)="tabClick()"
                 (click)="tabClick()">
   <h1>Some more tab content</h1>
</mat-tab>
Run Code Online (Sandbox Code Playgroud)

这就是功能,

tabClick(){
    console.log('Tab clicked...');
}
Run Code Online (Sandbox Code Playgroud)

但它似乎没有被称为,为什么?以上任何事件均未触发?

angular-material angular angular5 angular-material-5

6
推荐指数
2
解决办法
1万
查看次数

如何将Docker中的Kafka暴露给外界?

必须从 Docker 化的 Spring-Boot 应用程序与 Kafka 进行通信,\n我能够工作的唯一选择就是对 Kafka 进行 Docker 化。

\n\n

这是我的docker-compose-yml

\n\n
version: \'3.5\'\nservices:\n  zookeeper:\n    image: wurstmeister/zookeeper\n    ports:\n      - "2181:2181"\n    networks:\n      - kafka-network\n  kafka:\n    image: wurstmeister/kafka\n    ports:\n      - "9092:9092"\n    networks:\n      - kafka-network\n    environment:\n      KAFKA_ADVERTISED_HOST_NAME: kafka\n      KAFKA_AUTO_CREATE_TOPICS_ENABLE: \'true\'\n      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181\n    depends_on:\n      - zookeeper\n    volumes:\n      - /var/run/docker.sock:/var/run/docker.sock\nnetworks:\n  kafka-network:\n    name: kafka-network\n
Run Code Online (Sandbox Code Playgroud)\n\n

这样我就可以使用 url kafka:9092从kafka 网络上的另一个容器连接到 Kafka 代理

\n\n

如何使其也可以从本地主机和其他计算机上使用?

\n\n

更新\n我更新了我的 docker-compose,如下所示:

\n\n
version: \'3.5\'\nservices:\n  zookeeper:\n    image: wurstmeister/zookeeper\n    ports:\n      - "2181:2181"\n    networks:\n      - kafka-network\n  kafka:\n    image: …
Run Code Online (Sandbox Code Playgroud)

apache-kafka docker apache-zookeeper

6
推荐指数
1
解决办法
8062
查看次数

如何在 OAuth2 资源服务器中提取自定义主体?

我使用Keycloak作为我的 OAuth2 授权服务器,并按照GitHub上的官方示例配置了用于多租户的 OAuth2 资源服务器。考虑到JWT令牌的Issuer字段,当前租户已解决。因此,根据相应OpenID Connect众所周知端点处公开的JWKS来验证令牌。

这是我的安全配置:

@EnableWebSecurity
@RequiredArgsConstructor
@EnableAutoConfiguration(exclude = UserDetailsServiceAutoConfiguration.class)
public class OrganizationSecurityConfiguration extends WebSecurityConfigurerAdapter {

    private final TenantService tenantService;
    private List<Tenant> tenants;

    @PostConstruct
    public void init() {
        this.tenants = this.tenantService.findAllWithRelationships();
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests().anyRequest().authenticated()
                .and()
                .oauth2ResourceServer()
                .authenticationManagerResolver(new MultiTenantAuthenticationManagerResolver(this.tenants));
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我的自定义AuthenticationManagerResolver

public class MultiTenantAuthenticationManagerResolver implements AuthenticationManagerResolver<HttpServletRequest> {

    private final AuthenticationManagerResolver<HttpServletRequest> resolver;

    private List<Tenant> tenants;

    public …
Run Code Online (Sandbox Code Playgroud)

spring-security spring-boot spring-security-oauth2

6
推荐指数
1
解决办法
2610
查看次数

Lombok继承:如何在超类中设置字段的默认值而不重新声明它?

我正在使用 Lombok,我需要一种方法来自动设置子类中超类字段的值而无需重新声明它

当使用构建器时,它本身工作得很好(@SuperBuiler并且),但它在使用 Spring-Data MongoDB 时遇到了麻烦。@Builder.Default

org.springframework.data.mapping.MappingException: Ambiguous field mapping detected! Both protected test.jackson.polymorphism.domain.enumeration.EvaluationType test.jackson.polymorphism.domain.models.EvaluationModel.type and private test.jackson.polymorphism.domain.enumeration.EvaluationType test.jackson.polymorphism.domain.models.QuantitativeEvaluationModel.type map to the same field name type! Disambiguate using @Field annotation!

    at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$AssertFieldNameUniquenessHandler.assertUniqueness(BasicMongoPersistentEntity.java:368)
    at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$AssertFieldNameUniquenessHandler.doWithPersistentProperty(BasicMongoPersistentEntity.java:354)
    at org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity$AssertFieldNameUniquenessHandler.doWithPersistentProperty(BasicMongoPersistentEntity.java:348)
Run Code Online (Sandbox Code Playgroud)

这些是我的课程:

public enum EvaluationType{
    QUALITATIVE, QUANTITATIVE;
}
Run Code Online (Sandbox Code Playgroud)
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public abstract class EvaluationModel {
    protected EvaluationType type;
    protected Integer evaluation;
}
Run Code Online (Sandbox Code Playgroud)
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class QualitativeEvaluationModel extends EvaluationModel {
    /**
     * How to …
Run Code Online (Sandbox Code Playgroud)

java lombok

6
推荐指数
1
解决办法
3436
查看次数